Commit Graph

185 Commits

Author SHA1 Message Date
Simon Taylor
7622eb1d36 Finish the implementation of Aditi updates.
Estimated hours taken: 120

Finish the implementation of Aditi updates.

compiler/hlds_goal.m:
	Refactor the aditi_builtin type so that operations with
	similar syntax and implementations are grouped together.

	Add operations to delete a single tuple (`aditi_delete') and
	to modify tuples (`aditi_bulk_modify').

compiler/*.m:
	Minor changes required by refactoring the aditi_builtin type.

compiler/make_hlds.m:
	Parse `aditi_delete' and `aditi_bulk_modify' goals.

	Parse a nicer syntax for `aditi_bulk_delete' and
	`aditi_bulk_insert' goals
	(e.g. aditi_bulk_delete(p(_, X, _) :- X > 2)).

compiler/rl_out.pp:
	For each base relation, generate RL procedures to apply
	deletions and modifications to the relation. `aditi_bulk_modify'
	takes a closure which produces tuples which contain both the
	attributes of the tuple to delete and the tuple to insert. The
	modification RL procedure performs two projections on the
	closure result to produce the tuples to delete and the tuples
	to delete.

	The input stream to the rl_PROC_delete RL instruction must contain
	only tuples taken from the relation to delete from -- the deletion
	is done using the tuple-id rather than the tuple contents.
	The generated deletion procedure performs a semi-join of the
	relation to delete from with the relation containing the
	tuples to delete.

compiler/rl.m:
	Add predicates to generate the names of the modification
	and deletion RL procedures generated for each base relation.

compiler/rl_exprn.m:
	Generate the projection expressions required by the modification
	RL procedures generated for each base relation.

	Generate the equi-join expressions required by the modification
	and deletion RL procedures generated for each base relation.

compiler/unify_gen.m:
	Implement code generation for `aditi_bottom_up' closures.

compiler/rl.m:
compiler/magic.m:
	Factor out the code used to create the name of the RL procedure
	used to interface top-down Mercury to Aditi, for use by unify_gen.m
	to generate `aditi_bottom_up' closures.

compiler/code_util.m:
	Add predicate code_util__make_user_proc_label, which constructs
	a label name from the given all the individual pieces of information
	used to construct it, rather than just a pred_id and proc_id.
	This is used to produce the RL procedure name for an `aditi_bottom_up'
	closure, so that the code doesn't have to work out what the pred_id
	of the magic sets transformed procedure is.

compiler/magic.m:
	Always create new procedures to interface Mercury to Aditi,
	to make it easier for unify_gen.m to work out what the name
	of the interface procedure is -- don't optimize the case of
	a predicate with no input arguments.

	Alter the goal generated for the interface procedures so
	that it doesn't matter whether the interface procedure
	and the procedure it interfaces to are compiled together
	by rl_gen.m -- the old code generated for these procedures
	assumed they were compiled separately, which wasn't always the
	case.

	Don't pass a `magic_info' through the code to generate the
	C interface procedures -- only the module_info field was
	required.

compiler/magic_util.m:
compiler/magic.m:
compiler/context.m:
	Don't pass a `magic_info' through
	magic_util__create_input_test_unifications --
	only the module_info and proc_info fields were used.

compiler/post_typecheck.m:
compiler/magic_util.m:
	Don't report errors for the second `aditi__state' argument
	of the closure passed to `aditi_bulk_modify'.

compiler/purity.m:
	Change the mode of the second `aditi__state' argument
	of the closure passed to `aditi_bulk_modify' to `unused'.

compiler/call_gen.m:
	Generate `aditi_delete' and `aditi_bulk_modify'.

	Remove the `aditi__state' from the tuple to insert passed
	to an `aditi_insert' or `aditi_delete' operation -- the relation
	on disk does not contain the `aditi__state' attribute.

extras/aditi/aditi.m:
	Implement the updates.

	Allocate all memory on the Mercury heap to avoid memory
	leaks when a transaction aborts.

	Uncaught exceptions within a transaction now cause
	the transaction to abort, and the exception is rethrown
	to the caller.

	If using trailing, add trail entries for the output relation
	and cursor created for a call to an Aditi procedure, so that
	they will be cleaned up if only one solution of the call
	is needed or if an exception is thrown.

	Include line numbers in the debugging messages if an Aditi API
	function fails.

compiler/llds.m:
compiler/*.m:
	Rename the `do_aditi_modify' label to `do_aditi_bulk_modify' -- we
	may eventually want to implement a modification goal type which
	doesn't produce all modified tuples before applying the update.

doc/reference_manual.texi:
	Document `aditi_delete' and `aditi_bulk_modify'.

	Add some extra spacing in the Aditi update section to
	improve readability.

tests/valid/aditi_update.m:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_mode_errors.m:
tests/invalid/aditi_update_mode_errors.err_exp:
	Changed to fit in with the new syntax.

tests/valid/Mmakefile:
	Code generation for Aditi updates now works, so enable full
	compilation of the aditi_update.m test case, rather than
	just checking for errors.
2000-04-14 08:39:24 +00:00
David Jeffery
281796aa9a Make an addition to the type class info structure; add type infos for
Estimated hours taken: 10

Make an addition to the type class info structure; add type infos for
any type variables from the head of the instance declaration which are
unconstrained, and make the class method call mechanism insert these as
arguments to method calls. The implementations of methods expect to be passed
a type info for each unconstrained type variable and a type class info for
each constraint. Previously we were not passing the appropriate type infos.

Also move the documentation about the type class transformation from
polymorphism.m to a new file, compiler/notes/type_class_transformation.html.

compiler/base_typeclass_info.m:
        Generate the appropriate part of the new structure in the
        base_typeclass_info.
compiler/polymorphism.m:
        Add the appropriate type infos to the typeclass_info.
compiler/type_util.m:
        Add a new predicate `get_unconstrained_tvars'.
runtime/mercury_deep_copy_body.h:
        Update copy_typeclass_info to reflect the new structure.
runtime/mercury_ho_call.c:
        Copy the extra type infos to the beginning of the arguments when
        doing a class method call.
runtime/mercury_type_info.h:
        Update the macros used to access the type class info.

compiler/notes/type_class_transformation.html:
        The documentation about the type class transformation has been
        moved from polymorphism.m to here. This change corrects that
        documentation in several places and updates that documentation to
        reflect the changes to the typeclass_info structure from this diff.

tests/hard_coded/typeclasses/instance_unconstrained_tvar.exp:
tests/hard_coded/typeclasses/instance_unconstrained_tvar.m:
        A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
        Turn this test case on. For the moment, type specialisation is
        turned off for this test case as the specialiser does not insert the
        extra type infos that are needed.
2000-04-10 07:20:51 +00:00
Zoltan Somogyi
184e4710b1 Get the system to work with --no-special-preds, relying on RTTI interpretation
Estimated hours taken: 30

Get the system to work with --no-special-preds, relying on RTTI interpretation
to perform unifications and comparisons, in almost all cases. The only thing
that doesn't work is comparisons involving types with user-defined equality;
the generated exception does not get propagated across MR_call_engine
boundaries properly.

compiler/make_hlds.m:
	With --no-special-spreds, do not generate even declarations for
	type-specific index and compare predicates. Generate declarations
	and clauses for type-specific unify predicates, since we may need
	them for unifications that are not (in,in). However, we prevent
	the generation of code for the (in,in) case (i.e. mode 0) by pretending
	that the unify predicate is pseudo_imported, even in the module
	defining the type. There is one exception to this: for types with
	user-defined equality, we do generate a proper __Unify__ predicate,
	since this is the only convenient way to convert the specified
	sym_name of the equality predicate into a pred_id and proc_id,
	and a proper __Compare__ predicate, since this is the only convenient
	way to generate the full type name for the error message at runtime
	(due to polymorphism, the full type may not be known at compile time).
	(Finding the pred_id may require resolving type overloading,
	and finding the proc_id may require mode checking.)

compiler/simplify.m:
	When converting complicated unifications to calls, call the generic
	unify/2 and compare/3 predicates instead of the type-specific
	__Unify__ and __Compare__ predicates, if the latter do not exist.

compiler/higher_order.m:
	Do not specialize calls to the generic unify/2 and compare/3 predicates
	to type-specific __Unify__ and __Compare__ predicates, if the latter
	do not exist.

	Previously, we were not specializing comparisons of builtins and
	enumerations here, leaving it to inlining. In the absence of
	--special-preds, that doesn't work for enumerations, since there
	is no compiler-generated comparison predicate to do the inlining in.
	We therefore now perform both specializations.

compiler/polymorphism.m:
	Fix a bug: the code for looking up the special preds for user defined
	types was handling enums as builtins, which they are not: they can have
	user-defined equality.

compiler/type_ctor_info.m:
	Even with --no-special-preds, the type has type-specific __Unify_
	and __Compare__ predicates if it has user-defined equality. These
	predicates must be, and now are, put into the type_ctor_info.

runtime/mercury_wrapper.[ch]:
	Expand the facilities for collecting statistics about unify, index
	and compare operations. We used to collect only counts of operations
	for each type_ctor_rep; we now also collect counts of operations
	for each specific type. Rename MR_CTOR_REP_STATS as MR_TYPE_CTOR_STATS
	to reflect this expansion.

runtime/mercury_conf_param.h:
	Document MR_TYPE_CTOR_STATS instead of MR_CTOR_REP_STATS.

runtime/mercury_ho_call.c:
runtime/mercury_unify_compare_body.h:
	Fix a bug that showed with --no-special-preds: the Mercury predicate
	unify_2_0 cannot call the MR_generic_compare function to handle the
	arguments of a function symbol, because comparison is not defined
	on types with user-defined equality. Instead, we need to call the new
	MR_generic_unify C function, which does work on such types.

	Fix a bug that showed with --no-special-preds: the MR_succip register
	has to be saved and restored across calls to MR_generic_unify, since
	for types with user-defined equality, such calls involve a recursive
	invocation of the Mercury engine.

	Optimize the unification of du types by performing only one
	functor_desc lookup instead of two, and failing as early as possible.

	Use the new statistics facilities provided by mercury_wrapper.c.

tools/bootcheck
	If the new --type-stats option is given, preserve the type constructor
	statistics derived from (a) the stage 3 compilation process, and (b)
	compiling the test suite, for later analysis.

tools/type_ctor_stats:
	A new shell script to analyze type constructor statistics in their
	new, expanded format.

tests/hard_coded/user_defined_equality.{m,exp}:
	Test comparisons as well as unifications on enums with user-defined
	equality.
2000-04-05 06:29:12 +00:00
Zoltan Somogyi
c2a696d8b6 Clean up the runtime system's handling of type_infos and pseudo_type_infos.
Estimated hours taken: 40

Clean up the runtime system's handling of type_infos and pseudo_type_infos.
This cleanup has two major aspects. First, it represents type_infos and
pseudo_type_infos with distinct C types, and reducing the use of casts
to the minimum. These casts are in two kinds of places: in a few macros
defined in runtime/mercury_type_info.h, and at the interfaces between C code
and Mercury code (since Mercury code represents (pseudo-)type_infos, like
everything else, as Words). Part of this aspect is the separation of the
type "MR_TypeInfo" from the type "MR_TypeInfoParams"; a MR_TypeInfo can be
used as a source of type parameters directly only when it is first order.
Second, it removes the confusion between the types named "type_info" and
"type_ctor_info" defined by the modules private_builtin.m and std_util.m,
by renaming the types defined in std_util.m to "type_desc" and
"type_ctor_desc".

To avoid doing this cleanup twice, this diff also removes support for the
old type_ctor_info representation. This in turn makes it feasible to provide
conditionally enabled code to support unification and comparison by RTTI.

runtime/mercury_grade.h:
	Increment the binary compatibility version number. This is required
	by the dropping of support for old type_ctor_info representations.

runtime/mercury_type_info.h:
	Define the types MR_TypeInfo, MR_PseudoTypeInfo and MR_TypeInfoParams,
	and macros that operate on them.

	Remove the types and macros that were useful only with the old RTTI
	representation.

	Move the section that deals with initializing code addresses in
	type_ctor_info structure for grades without static code addresses
	to the logical place.

	Add a const qualifier to the MR_sectag_alternatives field in
	MR_DuPtagLayout, since this simplifies code manipulating du types.

	Convert the whole file to 4 space indentation, since it is a nuisance
	if only part of it is so indented.

runtime/mercury_deep_copy.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.h:
runtime/mercury_tabling.c:
	Clean up the implementation as described above.

runtime/mercury_type_info.c:
runtime/mercury_make_type_info_body.h:
	Clean up the implementation as described above.

	Eliminate the code duplication between the function MR_make_type_info
	and MR_create_type_info, and their helpers, which do the same thing
	except for how they allocate memory, by putting the common code into
	the new file mercury_make_type_info_body.h, and including it twice
	in two different #define contexts.

	Move the (updated) documentation of those functions to
	mercury_type_info.h, where it belongs.

runtime/mercury_ho_call.c:
runtime/mercury_unify_compare_body.h:
	Clean up the implementation as described above.

	Eliminate the code duplication between the implementation of unify
	and compare, which do very similar jobs, by putting the common code
	into the new file mercury_unify_compare_body.h, and including it three
	times in two different #define contexts. The third time is for defining
	the body of a C function which does the same thing as compare. This
	is necessary for unification and comparison by RTTI, since the
	unification or comparison of two structured terms requires comparing
	their subterms. (There is no need for a separate C function for
	unification; the C comparison function is sufficient.)

	mercury_unify_compare_body.h has conditional support for unification
	and comparison by RTTI. Although this has been tested and is known
	to work, it is turned off for the moment. This may change after
	benchmarking.

runtime/Mmakefile:
	Add the new include files to the list.

library/std_util.m:
	Rename type_info to type_desc and type_ctor_info to type_info_desc.
	Keep the old names as equivalence types, for the time being.
	Document the representations.

	Move the macros that refer to type_descs and type_ctor_descs here from
	runtime/mercury_type_info.h, since this is the only place where they
	are used. Rename them to conform to the new names of the types.

	Clean up the implementation of the RTTI predicates and functions
	as described above. In the process, fix some bugs where type variables
	were expanded twice, with the second expansion's code being incorrect.
	Also factor out some common code, and unfactor some uncommon code
	(where a function had two uses, but its implementation was inefficient
	overkill for one of them).

library/builtin.m:
library/private_builtin.m:
library/io.m:
library/store.m:
runtime/mercury_layout_util.[ch]:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_vars.[ch]:
	When calling C functions involving type_infos, cast them to the new
	types.

runtime/mercury_stack_layout.h:
	Fix a bug that was masked by casts in its client code.

compiler/rtti_out.m:
	Delete from the output a cast made unnecessary by the new const
	qualifier on MR_sectag_alternatives.

browser/browse.m:
browser/help.m:
library/io.m:
library/term.m:
tests/hard_coded/construct.m;
tests/hard_coded/existential_types_test.m:
tests/hard_coded/higher_order_type_manip.{m,exp}:
	Refer to the types defined in std_util.m by their new names.

tests/hard_coded/existential_rtti.{m,exp}:
	Make the test tougher by printing out not just one deconstructed term,
	but deconstructed versions of all the terms created by this test.
2000-03-24 10:28:07 +00:00
David Jeffery
6434c9a02e Include the number of typeclass methods in the base_typeclass_info
Estimated hours taken: 0.25

Include the number of typeclass methods in the base_typeclass_info
structure, making the structure self-describing. This information
is not used at the moment, but may be useful.

compiler/base_typeclass_info.m:
        Add the new information.
compiler/polymorphism.m:
        Update the documentation.
runtime/mercury_type_info.h:
        Update and add macros for the new structure.
2000-01-17 03:39:29 +00:00
Simon Taylor
5940825cdb Implement syntax for getting and setting fields of constructors.
Estimated hours taken: 70

Implement syntax for getting and setting fields of constructors.

compiler/make_hlds.m:
	Add information about field definitions to the module_info.

	Check that user-defined field access functions for exported
	fields are also exported, otherwise predicates in other modules
	could use a different method to access a field than predicates
	in module defining the field.
	Add a `predicate preds_add_implicit_report_error' to allow that check
	to be performed for functions which are added to the module_info
	by some means other than a `:- func' declaration.

	Parse field access goals and expressions.

	Add predicates `insert_arg_unifications_with_supplied_contexts',
	and `append_arg_unification', which allow more control over
	the contexts given to the added unifications. These are
	useful because the field value for an update is really an
	argument of the inner-most update function call, while the
	input term is an argument of the outer-most function call.

compiler/prog_io_dcg.m:
	Allow DCG goals of the form `:=(DCGArg)', which unifies `DCGArg'
	with the output DCG argument, ignoring the input DCG argument.
	The rationale for this change is that if we have convenient syntax
	for updating parts of a DCG argument, we should also have convenient
	syntax for updating the whole DCG argument.

compiler/typecheck.m:
	Add a default clause for field access functions for which
	the user has supplied type and mode declarations but no
	clauses.

	Typecheck field access function calls.

	Use `io__write_list' to remove some duplication of code
	to write out comma separated lists of error descriptions.

compiler/post_typecheck.m:
	Expand field accessor goals into the equivalent unifications.
	They are expanded inline rather than generating new get and set
	predicates for field name to avoid having to work out how to mode
	the generated predicates.

	Remove an unnecessary goal traversal to qualify function
	calls and constructors. That code is now called from purity.m.

compiler/prog_data.m:
compiler/prog_io.m:
compiler/mercury_to_goedel.m:
compiler/mercury_to_mercury.m:
	Store field names as `sym_name's rather than strings.
	Use a `maybe' type rather than an empty string to designate
	an unlabelled field.

compiler/hlds_data.m:
	Define data structures to hold information about
	the field names visible in a module.

compiler/hlds_module.m:
	Add a field to type module_info to hold information
	about the fields visible in a module.

compiler/hlds_pred.m:
	Add predicates to identify field access function names,
	and to handle the arguments of field access functions.

compiler/make_hlds.m:
compiler/hlds_goal.m:
compiler/modecheck_call.m:
compiler/higher_order.m:
compiler/purity.m:
compiler/polymorphism.m:
compiler/dnf.m:
compiler/cse_detection.m:
compiler/lambda.m:
	Move `create_atomic_unification' from make_hlds.m to hlds_goal.m
	because it is used by several other modules.

compiler/hlds_goal.m:
	Add a version of goal_info_init which takes the context of
	the goal, for use by make_hlds.m.

compiler/type_util.m:
	Add a predicate `type_util__get_type_and_cons_defn' to
	get the hlds_type_defn and hlds_cons_defn for a user-defined
	constructor.

compiler/prog_util.m:
	Add predicates to add and remove prefixes or suffixes
	from the unqualified part of a sym_name.

compiler/prog_out.m:
	Add a predicate to convert a `sym_name/arity' to a string.

compiler/hlds_out.m:
	Add `hlds_out__simple_call_id_to_string' to convert a
	`pred_or_func - sym_name/arity' to a string for use in
	error messages.

compiler/purity.m:
	Thread through the pred_info so that the expansion of field accessor
	goals can add new variables.

compiler/mercury_to_mercury.m:
library/ops.m:
	Reduce precedence of `^/2' for use as a field name separator.

	Add operator `^'/1 to designate which side of the `:=' is
	the field name in a DCG field access goal.

	Add operator `:=/2' for field update expressions.

doc/reference_manual.texi:
	Document the new syntax.

doc/transition_guide.texi:
	Document the new operators.

tests/hard_coded/Mmakefile:
tests/hard_coded/record_syntax.m:
tests/hard_coded/record_syntax.exp:
tests/invalid/Mmakefile:
tests/invalid/record_syntax_errors.m:
tests/invalid/record_syntax_errors.err_exp:
	Test cases.
2000-01-13 06:19:43 +00:00
David Jeffery
f62d759c2e Update the documentation describing the layout of a base_typeclass_info
Estimated hours taken: 0.25

compiler/polymorphism.m:
        Update the documentation describing the layout of a base_typeclass_info
        to include the new information introduced in my recent changes to
        the RTTI.
2000-01-10 05:55:37 +00:00
Simon Taylor
17cd4afa40 Fix a bug in my last change - some imports in the interface
Estimated hours taken: 0.1

compiler/polymorphimsm.m:
	Fix a bug in my last change - some imports in the interface
	should have been in the implementation.
1999-12-03 13:38:48 +00:00
Simon Taylor
38dfae4f7c Implement handling of typeclasses for inter-module optimization.
Estimated hours taken: 15

Implement handling of typeclasses for inter-module optimization.

compiler/hlds_data.m:
compiler/*.m:
	Add fields to type hlds_class_defn for use by intermod.m
	- the import_status of the `:- typeclass' declaration.
	- the original class interface from the `:- typeclass' declaration.

compiler/intermod.m:
	Write all local typeclasses, instances, types, insts and modes to
	the `.opt' file, instead of trying to work out which are needed.
	The old code to do this missed some types, insts and modes
	(test case tests/valid/intermod_test.m).

compiler/polymorphism.m:
	Expand class method bodies for imported predicates so that
	method lookups for those classes can be optimized.

compiler/hlds_pred.m:
compiler/check_typeclass.m:
compiler/higher_order.m:
compiler/hlds_out.m:
	Add a marker `class_instance_method', used to identify predicates
	introduced by check_typeclass.m to call the methods for each instance.

	Don't export `check_typeclass__introduced_pred_name_prefix/0' -
	higher_order.m now checks for a `class_instance_method' marker
	instead.

compiler/dead_proc_elim.m:
	Analyse all instance declarations, not just those defined in
	the current module, so that declarations for imported instance
	methods are not removed before method lookups have been specialized.

tests/valid/Mmakefile:
tests/valid/intermod_test.m:
tests/valid/intermod_test2.m:
	Check that nested types and modes are written to the `.opt' file.

tests/valid/intermod_typeclass.m:
tests/valid/intermod_typeclass2.m:
	Check that local typeclass and instance declarations are written
	to the `.opt' file.
1999-12-03 12:55:23 +00:00
Simon Taylor
f71e59b6de Improve the comment describing when goals need to be requantified.
Estimated hours taken: 0.1

compiler/polymorphism.m:
	Improve the comment describing when goals need to be requantified.
1999-10-26 01:01:06 +00:00
Fergus Henderson
d551dd1dc9 Handle quantification analysis of bi-implication (`<=>') goals correctly.
Estimated hours taken: 10

Handle quantification analysis of bi-implication (`<=>') goals correctly.
Previously we used to expand bi-implications before doing quantification
analysis, which stuffed up the results of quantification analysis for
those goals.  We need to do quantification analysis first, and only
then can we expand bi-implications.  In addition, elimination of double
negation needs to come after expansion of bi-implication, so I moved
that from make_hlds.m to purity.m.

compiler/hlds_goal.m:
	Add a new alternative to the HLDS goal type for bi-implications.
        Also add a new predicate negate_goal, for use by purity.m.

compiler/make_hlds.m:
	Don't expand bi-implication here, instead just use the new
	bi_implication/2 HLDS goal type.
	Don't eliminated double negation here.

compiler/quantification.m:
	Handle quantification for bi-implications.
	Expand bi-implications.

compiler/purity.m:
	Eliminate double negation.

compiler/hlds_out.m:
	Add code to print out bi-implication goals.

compiler/*.m:
	Trivial changes to handle the new bi_implication/2
	alternative in the HLDS goal type.

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

tests/hard_coded/Mmakefile:
tests/hard_coded/quantifier2.m:
tests/hard_coded/quantifier2.exp:
	A regression test for the above change.
1999-10-25 03:53:14 +00:00
Simon Taylor
0e07b6a20d Fix a spurious mode error for constructions involving
Estimated hours taken: 0.25

Fix a spurious mode error for constructions involving
existentially typed constructors.

compiler/polymorphism.m:
	Add the type-info variables added for the existential
	type variables of a constructor to the non-locals of
	the construction.

tests/valid/Mmakefile:
tests/valid/existential_cons.m:
	Test case.
1999-10-25 01:42:30 +00:00
Fergus Henderson
34d52a4091 Fix a bug with switches on existential types.
Estimated hours taken: 12

Fix a bug with switches on existential types.  This bug meant that
existential types with two or more functors did not work at all,
due to internal compiler errors when compiling the unification and
comparison predicates for those types.

compiler/type_util.m:
	Add new function cons_id_adjusted_arity, which computes the
	arity _including_ the extra typeinfo and typeclassinfo
	arguments inserted for existential data types.

compiler/type_util.m:
compiler/polymorphism.m:
	Move the predicates constraint_list_get_tvars
	and constraint_get_tvars from polymorphism.m into
	type_util.m, for use in cons_id_adjusted_arity.

compiler/modes.m:
compiler/unique_modes.m:
	When modechecking the functor test in switch statements,
	use cons_id_adjusted_arity to compute the arity of the inst,

compiler/instmap.m:
	In instmap__bind_var_to_functor (and the instmap_delta version),
	use cons_id_adjusted_arity to compute the arity of the inst.

compiler/goal_util.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/saved_vars.m:
compiler/mode_util.m:
compiler/deforest.m:
compiler/follow_code.m:
compiler/higher_order.m:
compiler/simplify.m:
	Pass the type(s) down to recompute_instmap_delta and
	instmap__bind_var_to_functor, since cons_id_adjusted_arity
	needs to know the type.

compiler/hlds_pred.m:
compiler/hlds_out.m:
	Add a `vartypes' typedef, defined by `:- type vartypes == map(prog_var, type)',
	and make use of it.  Rename the `vartypes' type in hlds_out as `maybe_vartypes'.

tests/hard_coded/Mmakefile:
tests/hard_coded/existential_type_switch.m:
tests/hard_coded/existential_type_switch.exp:
	Add a regression test.

tests/hard_coded/Mmakefile:
	Enable the existential_types_test.m test case,
	which should have been enabled previously.
	(The reason that it wasn't seems to be that I made
	a mistake when merging in the changes from the
	existential types branch.)
1999-10-15 03:45:27 +00:00
Simon Taylor
00df2750bd Remove the limitation of user-guided type specialization that
Estimated hours taken: 50

Remove the limitation of user-guided type specialization that
the replacement types must be ground.

compiler/higher_order.m:
	Only add extra type-infos, not typeclass-infos when
	--typeinfo-liveness is set, extracting type-infos from
	typeclass-infos where necessary. The arguments of the
	specialized version are now independent of the class context
	of the requesting procedure, which maximises the chance of multiple
	specialized calls to the same procedure being able to use the
	same code. The code to specialize calls is now slightly simpler
	because it does not have to work out how to order extra
	typeclass-info arguments.

	Specialize special preds for no-tag types where the
	wrapped type is an atomic type and the no-tag type does not
	have a user-defined equality pred. This will be useful
	for specializations involving type `term__var/1'.

	Make sure the proc_infos for specialized procedures are
	valid before reanalyzing the goals requesting the
	specializations.

	Rework the handling of branched goals to ensure that pred_infos
	and proc_infos are single threaded through branched goals - when
	higher_order.m was first written they were constant.

	Always go over all procedures for every predicate to make
	sure unifications are specialized in all procedures.

compiler/make_hlds.m:
	Check for type variables substituted multiple times
	or occurring on both sides of the substitution.

	Adjust the arity for specializations of functions.

compiler/polymorphism.m:
	Make sure the vartypes field for imported procedures is valid
	by copying it from the clauses_info to the proc_info.

compiler/polymorphism.m:
compiler/simplify.m:
compiler/table_gen.m:
compiler/magic.m:
	Remove an unused argument from polymorphism__make_type_info_vars.

compiler/type_util.m:
compiler/det_analysis.m:
	Add a predicate `type_util__type_has_user_defined_equality_pred'
	replacing similar code in det_analysis.m.

compiler/post_typecheck:
	Don't overwrite the vartypes field in the pred_info for
	automatically generated unification procedures for imported types.

library/varset.m:
	Add predicates `varset__merge_without_names' and
	`varset__merge_subst_without_names'.

compiler/equiv_type.m:
	Use the new predicates in varset.m to avoid adding the variable
	names from the declarations of equivalence types into the tvarsets
	of declarations which use those types. This is needed so that
	`varset__create_name_var_map' (used by make_hlds.m for
	`:- pragma type_spec' declarations and explicit type qualifications)
	is not confused by multiple occurrences of a variable name.

doc/reference_manual.texi:
	Remove documentation of the limitation that the substituted types
	must be ground.

tests/hard_coded/type_spec.m:
tests/hard_coded/type_spec.err_exp:
	Tests for non-ground substitutions and specialization of
	unification of no-tag types.

tests/invalid/type_spec.err_exp:
	Remove the error for a non-ground substitution.
	Add tests for recursive type substitutions and type variables
	with multiple replacement types.
1999-10-03 04:17:29 +00:00
Simon Taylor
97aead8a4a Don't specialize calls to unify/2, index/2 and compare/3 into
Estimated hours taken: 0.5

compiler/polymorphism.m:
	Don't specialize calls to unify/2, index/2 and compare/3 into
	type-specific versions here because it stuffs up the predicate
	names in mode error messages. The optimization is done in
	higher_order.m.

tests/invalid/Mmakefile:
tests/invalid/unify_mode_error.m:
tests/invalid/unify_mode_error.err_exp:
	Test case.
1999-09-21 07:10:22 +00:00
Peter Ross
79ab7d373d Extend the assertion system by
Estimated hours taken: 56

Extend the assertion system by
    * handling assertions in the interface of a module differently to
      those in the implementation.
    * testing an assertion for the commutivity property.


compiler/polymorphism.m:
    Remove the resolving of function calls and data constructors, do it
    in post_typecheck instead so that assertions are fully resolved.

compiler/post_typecheck.m:
    Add the resolving of function calls and data constructors.
    Also call assertion__in_interface_check, if an assertion is in the
    interface.

compiler/purity.m:
    post_typecheck__finish_assertion can now print error messages so
    pass the io__states.

compiler/hlds_data.m:
    Add assertion_table_pred_ids, so that intermod knows which pred_ids
    are assertions.

compiler/hlds_out.m:
    Add predicate hlds_out__write_assertion, which is used by intermod
    to write assertions to .opt files.
    Change the behaviour of outputing a call, so that if the call is a
    function it gets written out in functional syntax.  This is
    necessary because the resolving of function symbols now occurs in
    post_typecheck (pre writing .opt files) rather than in polymorphism
    (post writing .opt files).

compiler/intermod.m:
    Change intermod so that it writes out any assertion in the
    interface to the .opt file.

compiler/modules.m:
    Ensure that assertions in the interface are not written to the
    .int files.  Assertions should only appear in .opt files.

compiler/dead_proc_elim.m:
    When intermodule optimization is turned on dead_proc_elim gets run
    before typechecking and the assertion predicates are removed.  This
    change makes dead_proc_elim keep assertions.

compiler/make_hlds.m:
    The head variables for an assertion are already known, so initialise
    the clause_info structure to those variables rather then creating
    Arity fresh variables.
    Also don't insert unifications with the head of the assertion, since
    we already know that only variables are in the head.

compiler/goal_util.m:
    Add mode `goal_calls_pred_id(in, out) is nondet' for use by
    assertion__record_preds_used_in.

compiler/assertion.m:
    Add a predicate assertion__is_comutativity_assertion, which given
    an assertion_id determines whether or not that assertion declares
    the commutivity of a pred/func.
    Add a predicate assertion__in_interface_check, which checks that an
    assertion doesn't refer to any constructors, functions and
    predicates defined in the implementation of that module (note
    doesn't handle modules imported in the implementation section
    correctly).
    Rewrite assertion__record_preds_used_in to use the nondet mode of
    goal_calls_pred_id.

compiler/accumulator.m:
    Remove the facts which declare '+' and '*' to be commutative, and
    instead use the new assertion__is_commutivity_assertion predicate.
    Also remove the bool from assoc_fact which is the commutivity of the
    predicate, since only associative predicates reside in the table
    now.

library/int.m:
    Add commutivity declarations for '+' and '*', now that they have
    been removed from the assoc_fact table.  This allows me to test that
    all of these changes actually work!

compiler/hlds_goal.m:
    Clear up the documentation (I hope) for the type call_unify_context,
    so that it is clear that the unification may also have been a
    function application.

doc/reference_manual.texi:
doc/transition_guide.texi:
    Document assertions.
1999-09-12 04:27:36 +00:00
David Jeffery
6017919521 Rather that map__det_inserting the type info locations into the varmap,
Estimated hours taken: 0.5
        (but much more trying to get the @#$%! debugger working!)

compiler/polymorphism.m:
        Rather that map__det_inserting the type info locations into the varmap,
        map__set them: a type info may appear in more than one location if
        the type variable appears more than once in a constraint.

tests/valid/typeclass_multi_repeat.m:
        A test case for this.
tests/valid/Mmakefile:
        Add the test case.
1999-08-26 07:17:37 +00:00
David Jeffery
c9d753dfec Make the type and type class info varmaps and the varset valid for
Estimated hours taken: 1.5

compiler/polymorphism.m:
	Make the type and type class info varmaps and the varset valid for
	imported procedures.
1999-07-27 05:57:34 +00:00
Simon Taylor
2725b1a331 Aditi update syntax, type and mode checking.
Estimated hours taken: 220

Aditi update syntax, type and mode checking.

Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.

compiler/hlds_goal.m:
	Merge `higher_order_call' and `class_method_call' into a single
	`generic_call' goal type. This also has alternatives for the
	various Aditi builtins for which type declarations can't
	be written.

	Remove the argument types field from higher-order/class method calls.
	It wasn't used often, and wasn't updated by optimizations
	such as inlining. The types can be obtained from the vartypes
	field of the proc_info.

	Add a `lambda_eval_method' field to lambda_goals.

	Add a field to constructions to identify which RL code fragment should
	be used for an top-down Aditi closure.

	Add fields to constructions to hold structure reuse information.
	This is currently ignored -- the changes to implement structure
	reuse will be committed to the alias branch.
	This is included here to avoid lots of CVS conflicts caused by
	changing the definition of `hlds_goal' twice.

	Add a field to `some' goals to specify whether the quantification
	can be removed. This is used to make it easier to ensure that
	indexes are used for updates.

	Add a field to lambda_goals to describe whether the modes were
	guessed by the compiler and may need fixing up after typechecking
	works out the argument types.

	Add predicate `hlds_goal__generic_call_id' to work out a call_id
	for a generic call for use in error messages.

compiler/purity.m:
compiler/post_typecheck.m:
	Fill in the modes of Aditi builtin calls and closure constructions.
	This needs to know which are the `aditi__state' arguments, so
	it must be done after typechecking.

compiler/prog_data.m:
	Added `:- type sym_name_and_arity ---> sym_name/arity'.

	Add a type `lambda_eval_method', which describes how a closure
	is to be executed. The alternatives are normal Mercury execution,
	bottom-up execution by Aditi and top-down execution by Aditi.

compiler/prog_out.m:
	Add predicate `prog_out__write_sym_name_and_arity', which
	replaces duplicated inline code in a few places.

compiler/hlds_data.m:
	Add a `lambda_eval_method' field to `pred_const' cons_ids and
	`pred_closure_tag' cons_tags.

compiler/hlds_pred.m:
	Remove type `pred_call_id', replace it with type `simple_call_id',
	which combines a `pred_or_func' and a `sym_name_and_arity'.

	Add a type `call_id' which describes all the different types of call,
	including normal calls, higher-order and class-method calls
	and Aditi builtins.

	Add `aditi_top_down' to the type `marker'.

	Remove `aditi_interface' from type `marker'. Interfacing to
	Aditi predicates is now handled by `generic_call' hlds_goals.

	Add a type `rl_exprn_id' which identifies a predicate to
	be executed top-down by Aditi.
	Add a `maybe(rl_exprn_id)'  field to type `proc_info'.

	Add predicate `adjust_func_arity' to convert between the arity
	of a function to its arity as a predicate.

	Add predicates `get_state_args' and `get_state_args_det' to
	extract the DCG state arguments from an argument list.

	Add predicate `pred_info_get_call_id' to get a `simple_call_id'
	for a predicate for use in error messages.

compiler/hlds_out.m:
	Write the new representation for call_ids.

	Add a predicate `hlds_out__write_call_arg_id' which
	replaces similar code in mode_errors.m and typecheck.m.

compiler/prog_io_goal.m:
	Add support for `aditi_bottom_up' and `aditi_top_down' annotations
	on pred expressions.

compiler/prog_io_util.m:
compiler/prog_io_pragma.m:
	Add predicates
	- `prog_io_util:parse_name_and_arity' to parse `SymName/Arity'
		(moved from prog_io_pragma.m).
	- `prog_io_util:parse_pred_or_func_name_and_arity to parse
		`pred SymName/Arity' or `func SymName/Arity'.
	- `prog_io_util:parse_pred_or_func_and_args' to parse terms resembling
		a clause head (moved from prog_io_pragma.m).

compiler/type_util.m:
	Add support for `aditi_bottom_up' and `aditi_top_down' annotations
	on higher-order types.

	Add predicates `construct_higher_order_type',
	`construct_higher_order_pred_type' and
	`construct_higher_order_func_type' to avoid some code duplication.

compiler/mode_util.m:
	Add predicate `unused_mode/1', which returns `builtin:unused'.
	Add functions `aditi_di_mode/0', `aditi_ui_mode/0' and
	`aditi_uo_mode/0' which return `in', `in', and `out', but will
	be changed to return `di', `ui' and `uo' when alias tracking
	is implemented.

compiler/goal_util.m:
	Add predicate `goal_util__generic_call_vars' which returns
	any arguments to a generic_call which are not in the argument list,
	for example the closure passed to a higher-order call or
	the typeclass_info for a class method call.

compiler/llds.m:
compiler/exprn_aux.m:
compiler/dupelim.m:
compiler/llds_out.m:
compiler/opt_debug.m:
	Add builtin labels for the Aditi update operations.

compiler/hlds_module.m:
	Add predicate predicate_table_search_pf_sym, used for finding
	possible matches for a call with the wrong number of arguments.

compiler/intermod.m:
	Don't write predicates which build `aditi_top_down' goals,
	because there is currently no way to tell importing modules
	which RL code fragment to use.

compiler/simplify.m:
	Obey the `cannot_remove' field of explicit quantification goals.

compiler/make_hlds.m:
	Parse Aditi updates.

	Don't typecheck clauses for which syntax errors in Aditi updates
	are found - this avoids spurious "undefined predicate `aditi_insert/3'"
	errors.

	Factor out some common code to handle terms of the form `Head :- Body'.
	Factor out common code in the handling of pred and func expressions.

compiler/typecheck.m:
	Typecheck Aditi builtins.

	Allow the argument types of matching predicates to be adjusted
	when typechecking the higher-order arguments of Aditi builtins.

	Change `typecheck__resolve_pred_overloading' to take a list of
	argument types rather than a `map(var, type)' and a list of
	arguments to allow a transformation to be performed on the
	argument types before passing them.

compiler/error_util.m:
	Move the part of `report_error_num_args' which writes
	"wrong number of arguments (<x>; expected <y>)" from
	typecheck.m for use by make_hlds.m when reporting errors
	for Aditi builtins.

compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
	Modecheck Aditi builtins.

compiler/lambda.m:
	Handle the markers for predicates introduced for
	`aditi_top_down' and `aditi_bottom_up' lambda expressions.

compiler/polymorphism.m:
	Add extra type_infos to `aditi_insert' calls
	describing the tuple to insert.

compiler/call_gen.m:
	Generate code for Aditi builtins.

compiler/unify_gen.m:
compiler/bytecode_gen.m:
	Abort on `aditi_top_down' and `aditi_bottom_up' lambda
	expressions - code generation for them is not yet implemented.

compiler/magic.m:
	Use the `aditi_call' generic_call rather than create
	a new procedure for each Aditi predicate called from C.

compiler/rl_out.pp:
compiler/rl_gen.m:
compiler/rl.m:
	Move some utility code used by magic.m and call_gen.m into rl.m.

	Remove an XXX comment about reference counting being not yet
	implemented - Evan has fixed that.

library/ops.m:
compiler/mercury_to_mercury.m:
doc/transition_guide.texi:
	Add unary prefix operators `aditi_bottom_up' and `aditi_top_down',
	used as qualifiers on lambda expressions.
	Add infix operator `==>' to separate the tuples in an
	`aditi_modify' call.

compiler/follow_vars.m:
	Thread a `map(prog_var, type)' through, needed because
	type information is no longer held in higher-order call goals.

compiler/table_gen.m:
	Use the `make_*_construction' predicates in hlds_goal.m
	to construct constants.

compiler/*.m:
	Trivial changes to add extra fields to hlds_goal structures.

doc/reference_manual.texi:
	Document Aditi updates.

	Use @samp{pragma base_relation} instead of
	@samp{:- pragma base_relation} throughout the Aditi documentation
	to be consistent with other parts of the reference manual.

tests/valid/Mmakefile:
tests/valid/aditi_update.m:
tests/valid/aditi.m:
	Test case.

tests/valid/Mmakefile:
	Remove some hard-coded --intermodule-optimization rules which are
	no longer needed because `mmake depend' is now run in this directory.

tests/invalid/*.err_exp:
	Fix expected output for changes in reporting of call_ids
	in typecheck.m.

tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
tests/invalid/aditi_update_mode_errors.{m,err_exp}:
	Test error messages for Aditi updates.

tests/valid/aditi.m:
tests/invalid/aditi.m:
	Cut down version of extras/aditi/aditi.m to provide basic declarations
	for Aditi compilation such as `aditi__state' and the modes
	`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
	somewhere would remove the need for these.
1999-07-13 08:55:28 +00:00
Fergus Henderson
8c97633e71 Allow construction unifications for existentially typed functors,
Estimated hours taken: 6

Allow construction unifications for existentially typed functors,
using the syntax "X = 'new foo'(Y)" rather than the usual "X = foo(Y)".
We need to use a special syntax for exisentially typed constructions
because type analysis and polymorphism need to know which occurrences
of existentially typed functors are constructors and which are deconstructors.

Note that we still don't yet support RTTI for existentially typed data types.

compiler/typecheck.m:
	For existentially typed functors, allow the functor to have
	a "new " prefix, and if so, make the quantifiers and constraints
	universal rather than existential.

compiler/polymorphism.m:
	For unifications with existentially typed functors,
	check for a "new " prefix on the functor.
	If the functor has such a prefix, strip off the prefix,
	and treat the unification as a construction rather than
	treating it as a deconstruction.

compiler/type_util.m:
	Define a new predicate `remove_new_prefix', for use by typecheck.m
	and polymorphism.m.

compiler/modecheck_unify.m:
	For construction unifications, check that all the type_info
	and typeclass_info arguments introduced by polymorphism.m
	are ground.

tests/hard_coded/typeclasses/existential_data_types.m:
	Change the test case to use this new feature,
	rather than hacking it using the C interface.

doc/reference_manual.texi:
	Document the new features.
1999-07-08 08:15:29 +00:00
Fergus Henderson
6f4970a41d Use more meaningful variable names, as suggested by dgj's code review.
Estimated hours taken: 0.25

compiler/polymorphism.m:
	Use more meaningful variable names, as suggested by dgj's code review.
1999-07-07 14:58:26 +00:00
Fergus Henderson
ec86c88404 Merge in the changes from the existential_types_2 branch.
Estimated hours taken: 4

Merge in the changes from the existential_types_2 branch.

This change adds support for mode re-ordering of code involving
existential types.  The change required modifying the order of the
compiler passes so that polymorphism comes before mode analysis,
so that mode analysis can check the modes of the `type_info' or
`typeclass_info' variables that polymorphism introduces, so that
it can thus re-order the code accordingly.

This change also includes some more steps towards making existential data
types work.  In particular, you should be able to declare existentially
typed data types, the compiler will generate appropriate unification
and compare/3 routines for them, and deconstruction unifications for them
should work OK.  However, currently there's no way to construct them
except via `pragam c_code', and we don't generate correct RTTI for them,
so you can't use `io__write' etc. on them.

library/private_builtin.m:
compiler/accumulator.m:
compiler/bytecode_gen.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/code_util.m:
compiler/common.m:
compiler/dead_proc_elim.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/live_vars.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mercury_compile.m:
compiler/mercury_to_c.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/mode_util.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/pd_cost.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/purity.m:
compiler/quantification.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/simplify.m:
compiler/table_gen.m:
compiler/term_traversal.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unused_args.m:
compiler/notes/compiler_design.html:
doc/reference_manual.texi:
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/existential_data_types.m:
tests/hard_coded/typeclasses/existential_data_types.exp:
tests/warnings/simple_code.exp:
tests/hard_coded/Mmakefile:
tests/term/arit_exp.trans_opt_exp:
tests/term/associative.trans_opt_exp:
tests/term/pl5_2_2.trans_opt_exp:
tests/term/vangelder.trans_opt_exp:
tests/term/arit_exp.trans_opt_exp:
tests/term/associative.trans_opt_exp:
tests/term/pl5_2_2.trans_opt_exp:
tests/term/vangelder.trans_opt_exp:
tests/invalid/errors2.err_exp2:
tests/invalid/prog_io_erroneous.err_exp2:
tests/invalid/type_inf_loop.err_exp2:
tests/invalid/types.err_exp2:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/Mmakefile:
tests/warnings/simple_code.exp:
tests/debugger/queens.exp:
tests/hard_coded/Mmakefile:
tests/hard_coded/existential_reordering.m:
tests/hard_coded/existential_reordering.exp:
	Merge in the changes from the existential_types_2 branch.
1999-06-30 17:13:53 +00:00
Simon Taylor
79dcbbef15 User-guided type specialization.
Estimated hours taken: 60

User-guided type specialization.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/modules.m:
compiler/module_qual.m:
compiler/mercury_to_mercury.m:
	Handle `:- pragma type_spec'.

compiler/prog_io_pragma.m:
	Factor out some common code to parse predicate names with arguments.

compiler/hlds_module.m:
	Added a field to the module_sub_info to hold information about
	user-requested type specializations, filled in by make_hlds.m
	and not used by anything after higher_order.m.

compiler/make_hlds.m:
	For each `:- pragma type_spec' declaration, introduce a new predicate
	which just calls the predicate to be specialized with the
	specified argument types. This forces higher_order.m to produce
	the specialized versions.

compiler/higher_order.m:
	Process the user-requested type specializations first to ensure
	that they get the correct names.
	Allow partial matches against user-specified versions, e.g.
		map__lookup(map(int, list(int)), int, list(int)) matches
		map__lookup(map(int, V), int, V).
	Perform specialization where a typeclass constraint matches a
	known instance, but the construction of the typeclass_info is
	done in the calling module.
	Give slightly more informative progress messages.

compiler/dead_proc_elim.m:
	Remove specializations for dead procedures.

compiler/prog_io_util.m:
	Change the definition of the `maybe1' and `maybe_functor' types
	to avoid the need for copying to convert between `maybe1'
	and `maybe1(generic)'.
	Changed the interface of `make_pred_name_with_context' to allow
	creation of predicate names for type specializations which describe
	the type substitution.

compiler/make_hlds.m:
compiler/prog_io_pragma.m:
	Make the specification of pragma declarations in error
	messages consistent. (There are probably some more to
	be fixed elsewhere for termination and tabling).

compiler/intermod.m:
	Write type specialization pragmas for predicates declared
	in `.opt' files.

compiler/mercury_to_mercury.m:
	Export `mercury_output_item' for use by intermod.m.

compiler/options.m:
	Add an option `--user-guided-type-specialization' enabled
	with `-O2' or higher.

compiler/handle_options.m:
	`--type-specialization' implies `--user-guided-type-specialization'.

compiler/hlds_goal.m:
	Add predicates to construct constants. These are duplicated
	in several other places, I'll fix that as a separate change.

compiler/type_util.m:
	Added functions `int_type/0', `string_type/0', `float_type/0'
	and `char_type/0' which return the builtin types.
	These are duplicated in several other places,
	I'll fix that as a separate change.

library/private_builtin.m:
	Added `instance_constraint_from_typeclass_info/3' to extract
	the typeclass_infos for a constraint on an instance declaration.
	This is useful for specializing class method calls.
	Added `thread_safe' to various `:- pragma c_code's.
	Added `:- pragma inline' declarations for `builtin_compare_*', which
	are important for user-guided type specialization. (`builtin_unify_*'
	are simple enough to go in the `.opt' files automatically).

compiler/polymorphism.m:
	`instance_constraint_from_typeclass_info/3' does not need type_infos.
	Add `instance_constraint_from_typeclass_info/3' to the
	list of `typeclass_info_manipulator's which higher_order.m
	can interpret.

NEWS:
doc/reference_manual.texi:
doc/user_guide.texi
	Document the new pragma and option.

tests/invalid/Mmakefile:
tests/invalid/type_spec.m:
tests/invalid/type_spec.err_exp:
	Test error reporting for invalid type specializations.

tests/hard_coded/Mmakefile:
tests/invalid/type_spec.m:
tests/invalid/type_spec.exp:
	Test type specialization.
1999-04-23 01:03:51 +00:00
Tyson Dowd
03e724c034 Start the changes needed to simplify type_ctor_*.
Estimated hours taken: 7

Start the changes needed to simplify type_ctor_*.

This simplification involves lifting the most important information
about the type representation out of type_ctor_layout and
type_ctor_functors and putting it into type_ctor_info.  In many
cases this will mean we can do without type_ctor_layout altogether,
and we will be able to remove the "functors indicator" from
type_ctor_functors.  The type_ctor_layout can be simplified quite a bit
because it only needs to describe discriminated unions.

compiler/base_type_info.m:
compiler/base_type_layout.m:
compiler/dead_proc_elim.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/polymorphism.m:
	Add code to generate the new MR_TypeCtorRepresentation
	field.
	Don't actually generate it yet, we need to bootstrap this
	change.  So we create two references to type_info_layouts
	instead.  When the compiler has bootstrapped we can change
	the runtime to use the later reference, and convert the
	earlier reference into MR_TypeCtorRepresentation.

library/builtin.m:
library/private_builtin.m:
runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
	Add the new field to type_ctor_infos defined in C.
	Fix a few minor bugs with these type_ctor_infos (incorrect
	lengths of string constants, lingering references to
	term_to_type preds.

runtime/mercury_type_info.h:
	Move the offset for type name and module name down one.
	This won't cause any bootstrapping problems because the compiler
	barely uses such names.

	Add new types:
		MR_TypeCtorInfo
			This struct will replace MR_TYPE_CTOR_INFO_*
			macros and offsets.

		MR_TypeCtorRepresentation
		MR_DiscUnionTagRepresentation
			Will replace the more expensive to compute
			MR_DataRepresentation.
1999-04-08 08:42:13 +00:00
Tyson Dowd
a5fcfcabcb Rename some missed references to base_type_* as type_ctor_* in
Estimated hours taken: 0.1

compiler/base_type_layout.m:
compiler/polymorphism.m:
compiler/type_util.m:
	Rename some missed references to base_type_* as type_ctor_* in
	some comments and an error message.
1999-03-24 03:11:13 +00:00
Tyson Dowd
1f312b45e9 During the writing of the RTTI paper, we decided that type_ctor_info
Estimated hours taken: 8

During the writing of the RTTI paper, we decided that type_ctor_info
was a much better name than base_type_info.

Rename base_type* as type_ctor*, except we don't rename the modules
base_type_info and base_type_layout just yet.

Most of these changes were made using the following sed patterns:

s/base_type_info/type_ctor_info/g
s/base_type_layout/type_ctor_layout/g
s/base_type_functors/type_ctor_functors/g
s/BASETYPE_INFO/TYPE_CTOR_INFO/g
s/TYPEFUNCTORS/TYPE_CTOR_FUNCTORS/g
s/TYPELAYOUT/TYPE_CTOR_LAYOUT/g
s/BASE_TYPEINFO/TYPE_CTOR_INFO/g
s/BASE_TYPE_INFO/TYPE_CTOR_INFO/g
s/BaseTypeInfo/TypeCtorInfo/g
s/BaseTypeLayout/TypeCtorLayout/g
s/base_type(/type_ctor(/g
s/:- module type_ctor_info/:- module base_type_info/g
s/:- module type_ctor_layout/:- module base_type_layout/g
s/type_ctor_info__/base_type_info__/g
s/type_ctor_layout__/base_type_layout__/g
/import_module/s/type_ctor_info/base_type_info/g
/import_module/s/type_ctor_layout/base_type_layout/g

compiler/*.m:
library/*.m:
runtime/*.{c,h}:
profiler/demangle.m:
util/mdemangle.c:
	Applied the above sed commands.

runtime/mercury_bootstrap.h:
	Add bootstrapping #defines so the type_ctor_* substitutions in
	the library don't cause link problems.

	Delete some redundant bootstrapping definitions.
1999-03-22 08:09:08 +00:00
David Jeffery
23884b50f8 Fix a bug whereby the @#$!% typeclass-infos nested inside another
Estimated hours taken: 25

Fix a bug whereby the @#$!% typeclass-infos nested inside another
typeclass-info (ie. from the constraints on an instance decl) were being
inserted in the reverse order. This caused the code to jump to the wrong
type class method.

compiler/polymorphism.m:
        Reverse the list of argument variables that we get back from
        polymorphism__make_typeclass_info_vars_2 because they are built
        up in reverse.

        Also fix a buggy comment about the order that the extra arguments
        are added in by this pass.

tests/hard_coded/typeclasses/implied_instance_multi_constraint.{m, exp}:
        A test case for this bug fix.
tests/hard_coded/typeclasses/Mmakefile:
        Add this test case.
1999-02-28 06:54:44 +00:00
Simon Taylor
18430aaef1 Aditi compilation.
Estimated hours taken: 1200

Aditi compilation.

compiler/options.m:
	The documentation for these is commented out because the Aditi
	system is not currently useful to the general public.
	--aditi: enable Aditi compilation.
	--dump-rl: write the intermediate RL to `<module>.rl_dump'.
	--dump-rl-bytecode: write a text version of the bytecodes
		to `<module>.rla'
	--aditi-only: don't produce a `.c' file.
	--filenames-from-stdin: accept a list of filenames to compile
		from stdin. This is used by the query shell.
	--optimize-rl, --optimize-rl-cse, --optimize-rl-invariants,
	--optimize-rl-index, --detect-rl-streams:
		Options to control RL optimization passes.
	--aditi-user:
		Default owner of any Aditi procedures,
		defaults to $USER or "guest".
	--generate-schemas:
		write schemas for base relations to `<module>'.base_schema
		and schemas for derived relations to `<module>'.derived_schema.
		This is used by the query shell.

compiler/handle_options.m:
	Handle the default for --aditi-user.

compiler/hlds_pred.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
	Add some Aditi pragma declarations - `aditi', `supp_magic', `context',
	`naive', `psn' (predicate semi-naive), `aditi_memo', `aditi_no_memo',
	`base_relation', `owner' and `index'.
	Separate out code to parse a predicate name and arity.

compiler/hlds_pred.m:
	Add predicates to identify Aditi procedures.
	Added markers `generate_inline' and `aditi_interface', which
	are used internally for Aditi code generation.
	Add an `owner' field to pred_infos, which is used for database
	security checks.
	Add a field to pred_infos to hold the list of indexes for a base
	relation.

compiler/make_hlds.m:
	Some pragmas must be exported if the corresponding predicates
	are exported, check this.
	Make sure stratification of Aditi procedures is checked.
	Predicates with a mode declaration but no type declaration
	are no longer assumed to be local.
	Set the `do_aditi_compilation' field of the module_info if there
	are any local Aditi procedures or base relations.
	Check that `--aditi' is set if Aditi compilation is required.

compiler/post_typecheck.m:
	Check that every Aditi predicate has an `aditi__state' argument,
	which is used to ensure sequencing of updates and that Aditi
	procedures are only called within transactions.

compiler/dnf.m:
	Changed the definition of disjunctive normal form slightly
	so that a call followed by some atomic goals not including
	any database calls is considered atomic. magic.m can handle
	this kind of goal, and it results in more efficient RL code.

compiler/hlds_module.m:
compiler/dependency_graph.m:
	Added dependency_graph__get_scc_entry_points which finds
	the procedures in an SCC which could be called from outside.
	Added a new field to the dependency_info, the
	aditi_dependency_ordering. This contains all Aditi SCCs of
	the original program, with multiple SCCs merged where
	possible to improve the effectiveness of differential evaluation
	and the low level RL optimizations.

compiler/hlds_module.m:
	Add a field to record whether there are any local Aditi procedures
	in the current module.
	Added versions of module_info_pred_proc_info and
	module_info_set_pred_proc_info which take a pred_proc_id,
	not a separate pred_id and proc_id.

compiler/polymorphism.m:
compiler/lambda.m:
	Make sure that predicates created for closures in Aditi procedures
	have the correct markers.

compiler/goal_util.m:
	Added goal_util__switch_to_disjunction,
	goal_util__case_to_disjunct (factored out from simplify.m)
	and goal_util__if_then_else_to_disjunction. These are
	require because supplementary magic sets can't handle
	if-then-elses or switches.

compiler/type_util.m:
	Added type_is_aditi_state/1.

compiler/mode_util.m:
	Added partition_args/5 which partitions a list of arguments
	into inputs and others.

compiler/inlining.m:
	Don't inline memoed procedures.
	Don't inline Aditi procedures into non-Aditi procedures.

compiler/intermod.m:
	Handle Aditi markers.
	Clean up handling of markers which should not appear in `.opt' files.

compiler/simplify.m:
	Export a slightly different interface for use by magic.m.
	Remove explicit quantifications where possible.
	Merge multiple nested quantifications.
	Don't report infinite recursion warnings for Aditi procedures.

compiler/prog_out.m:
	Generalised the code to output a module list to write any list.

compiler/code_gen.m:
compiler/arg_info.m:
	Don't process Aditi procedures.

compiler/mercury_compile.m:
	Call magic.m and rl_gen.m.
	Don't perform the low-level annotation passes on Aditi procedures.
	Remove calls to constraint.m - sometime soon a rewritten version
	will be called directly from deforestation.

compiler/passes_aux.m:
	Add predicates to process only non-Aditi procedures.

compiler/llds.m:
compiler/llds_out.m:
	Added new `code_addr' enum members, do_{det,semidet,nondet}_aditi_call,
	which are defined in extras/aditi/aditi.m.

compiler/call_gen.m:
	Handle generation of do_*_aditi_call.

compiler/llds_out.m:
	Write the RL code for the module as a constant char array
	in the `.c' file.

compiler/term_errors.m:
compiler/error_util.m:
	Move code to describe predicates into error_util.m
	Allow the caller to explicitly add line breaks.
	Added error_util:list_to_pieces to format a list of
	strings.
	Reordered some arguments for currying.

compiler/hlds_out.m:
	Don't try to print clauses if there are none.

runtime/mercury_init.h:
util/mkinit.c:
scripts/c2init.in:
	Added a function `mercury__load_aditi_rl_code()' to the generated
	`<module>_init.c' file which throws all the RL code for the program
	at the database. This should be called at connection time by
	`aditi__connect'.
	Added an option `--aditi' which controls the output
	`mercury__load_aditi_rl_code()'.

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

Mmakefile:
bindist/Mmakefile:
	Don't distribute extras/aditi yet.

New files:

compiler/magic.m:
compiler/magic_util.m:
	Supplementary magic sets transformation. Report errors
	for constructs that Aditi can't handle.

compiler/context.m:
	Supplementary context transformation.

compiler/rl_gen.m:
compiler/rl_relops.m:
	Aditi code generation.

compiler/rl_info.m:
	Code generator state.

compiler/rl.m:
	Intermediate RL representation.

compiler/rl_util:
	Predicates to collect information about RL instructions.

compiler/rl_dump.m:
	Print out the representation in rl.m.

compiler/rl_opt.m:
	Control low-level RL optimizations.

compiler/rl_block.m:
	Break a procedure into basic blocks.

compiler/rl_analyse.m:
	Generic dataflow analysis for RL procedures.

compiler/rl_liveness.m:
	Make sure all relations are initialised before used, clear
	references to relations that are no longer required.

compiler/rl_loop.m:
	Loop invariant removal.

compiler/rl_block_opt.m:
	CSE and instruction merging on basic blocks.

compiler/rl_key.m:
	Detect upper/lower bounds for which a goal could succeed.

compiler/rl_sort.m:
	Use indexing for joins and projections.
	Optimize away unnecessary sorting and indexing.

compiler/rl_stream.m:
	Detect relations which don't need to be materialised.

compiler/rl_code.m:
	RL bytecode definitions. Automatically generated from the Aditi
	header files.

compiler/rl_out.m:
compiler/rl_file.m:
	Output the RL bytecodes in binary to <module>.rlo (for use by Aditi)
	and in text to <module>.rla (for use by the RL interpreter).
	Also output the schema information if --generate-schemas is set.

compiler/rl_exprn.m:
	Generate bytecodes for join conditions.

extras/aditi/Mmakefile:
extras/aditi/aditi.m:
	Definitions of some Aditi library predicates and the
	interfacing and transaction processing code.
1998-12-06 23:49:14 +00:00
Warwick Harvey
89f7daacda Include a context in the error message output when polymorphic
Estimated hours taken: 3

Include a context in the error message output when polymorphic
unification is attempted with a non-ground instantiation.

compiler/polymorphism.m:
	Include a context in the error message output when polymorphic
	unification is attempted with a non-ground instantiation.

compiler/prog_out.m:
	Add a context_to_string/2 predicate, which writes a context to a
	string (rather than writing it out directly).
	Rearranged and cleaned up some of the related predicates to make
	use of the new predicate, to avoid code duplication and unnecessary
	runtime calls.
1998-12-03 07:01:19 +00:00
Thomas Conway
5c955626f2 These changes make var' and term' polymorphic.
Estimated hours taken: 20

These changes make `var' and `term' polymorphic. This allows us to make
variables and terms representing types of a different type to those
representing program terms and those representing insts.

These changes do not *fix* any existing problems (for instance
there was a messy conflation of program variables and inst variables,
and where necessary I've just called varset__init(InstVarSet) with
an XXX comment).

NEWS:
	Mention the changes to the standard library.

library/term.m:
	Make term, var and var_supply polymorphic.
	Add new predicates:
		term__generic_term/1
		term__coerce/2
		term__coerce_var/2
		term__coerce_var_supply/2

library/varset.m:
	Make varset polymorphic.
	Add the new predicate:
		varset__coerce/2

compiler/prog_data.m:
	Introduce type equivalences for the different kinds of
	vars, terms, and varsets that we use (tvar and tvarset
	were already there but have been changed to use the
	polymorphic var and term).

	Also change the various kinds of items to use the appropriate
	kinds of var/varset.

compiler/*.m:
	Thousands of boring changes to make the compiler type correct
	with the different types for type, program and inst vars and
	varsets.
1998-11-20 04:10:36 +00:00
David Jeffery
865bf8c5b8 Abort if there is a polymorphic unification that is in
Estimated hours taken: 2

compiler/polymorphism.m:
        Abort if there is a polymorphic unification that is in
        a partially instantiated mode. This error should be
        caught earlier (probably during mode analysis), but it's
        best to abort rather than just go ahead and generate
        bad code.

tests/invalid/polymorphic_unification.m:
tests/invalid/polymorphic_unification.err_exp:
        A test case for the above change.

tests/invalid/Mmakefile:
        Turn this test case on.
1998-11-09 05:28:40 +00:00
Fergus Henderson
9bc284e8ea Fix a bug that broke `mmc --debug tests/hard_coded/agg.m'.
Estimated hours taken: 1

Fix a bug that broke `mmc --debug tests/hard_coded/agg.m'.

compiler/polymorphism.m:
	When processing lambda expressions,
	add type_info variables for the argument
	variables, not just for the non-local variables.
	This is necessary for debugging in the case of
	lambda expressions with unused arguments.
1998-11-09 02:49:37 +00:00
David Jeffery
5ca73fbb82 Fix two bugs in polymorphism.m (one of which didn't show up until the other
Estimated hours taken: 8

Fix two bugs in polymorphism.m (one of which didn't show up until the other
was fixed). The test case for this fix is
tests/hard_coded/typeclasses/existential_type_class.m.

compiler/polymorphism.m:
        Don't map__det_insert existential typeclass_infos into the type class
        info map as they may already be there. (eg. when it is in two
        variables which get unified).

        Only add instmap_deltas for type info variables if the type info
        has its own variable. ie. it isn't inside a typeclass info.
1998-10-15 09:25:11 +00:00
Tyson Dowd
fd548396d8 Fix some comments about type classes.
Estimated hours taken: 0.5

compiler/polymorphism.m:
	Fix some comments about type classes.
	A few cut and paste errors mean it talked about type_info when
	it should be typeclass_info, and other potentially confusing
	mistakes.
1998-10-13 06:54:23 +00:00
David Jeffery
535afbcc18 Add existential type-infos and typeclass-infos to the appropriate location
Estimated hours taken: 7

Add existential type-infos and typeclass-infos to the appropriate location
maps. With --trace all on,

compiler/polymorphism.m:
        Add code to put the type-info and typeclass-info locations into the
        appropriate maps in several spots. Also delete some code which was
        deliberately throwing away exisential type-info locations.
tests/hard_coded/typeclasses/Mmakefile:
        Turn "--trace all" on for a test case which triggers this bug.
1998-10-03 04:36:49 +00:00
David Jeffery
ab5d46e271 Improve the error messages generated by check_typeclass.m.
Estimated hours taken: 10

Improve the error messages generated by check_typeclass.m.

check_typeclass.m:
        Write decent error messages, including term__contexts for the
        appropriate lines, for the errors detected by this module. These errors
        are missing or multiple definitions of instance methods and unsatisfied
        superclass constraints on instance decls.
mercury_to_mercury.m:
        Add predicates which convert class_constraints and types into strings.
        This is needed so that an error message can be created as a string,
        then formatted to fit the line, rather than writing out the error
        message as you go.
hlds_data.m:
        Add a term__context to the hlds_instance_defn.
base_typeclass_info.m:
dead_proc_elim.m:
higher_order.m:
hlds_out.m:
polymorphism.m:
typecheck.m:
        Ignore the term__context field of the hlds_instance_defn.
make_hlds.m:
        Insert the term__context field into the hlds_instance_defn when it
        is created.
1998-09-22 16:14:14 +00:00
David Jeffery
f05dc52d86 Fix a bug in the renaming of tvars in type class constraint proofs, and
Estimated hours taken: 20

Fix a bug in the renaming of tvars in type class constraint proofs, and
generally clean up the handling of variable renaming in polymorphism.m.

Change the representation of constraint_proofs to only hold the number of an
instance declaration and not the hlds_instance_defn itself. This means that
polymorphism must look up the instance table to get at hlds_instance_defn,
then calculate the appropriate renamings and substitutions. The rationale
behind this is that the proofs for the superclasses, stored in the
hlds_instance_defn, also need to be renamed. However, we can't just rename
them during typecheck.m because they may not contain proofs for *all* their
ancestors --- that would require topologically sorting the instance defns
before check_typeclass.m.

Also delete the code which attempts to specialise class method calls because
Simon's recent change does this anyway.

hlds_data.m:
        Change the constraint_proof representation to only hold instance
        numbers, not definitions.
polymorphism.m:
        When applying an instance decl, look it up in the instance table
        rather than trying to use the half-renamed one in the proof.

        Also, rather than trying to pass down a renaming substution into
        polymorphism__make_typeclass_info_var, rename everything before
        calling it.
type_util.m:
        Add two new predicates: apply_subst_to_constraint_proofs and
        apply_rec_subst_to_constraint_proofs.
typecheck.m:
        Only store the instance number in the proof.
1998-09-18 02:20:43 +00:00
Simon Taylor
3e244090d7 Rework the handling of types in higher_order.m.
Estimated hours taken: 50

Rework the handling of types in higher_order.m.
- Fix bugs in higher_order.m that stopped it working with --typeinfo-liveness.
- Perform type and typeclass specialisation.

compiler/polymorphism.m:
	Previously the type of typeclass_infos variables did not contain
	any information about the constraint about which the variable contains
	information. Now the type of a typeclass_info is
	`private_builtin:typeclass_info(
		private_builtin:constraint([ClassName, ConstrainedTypes]))'.
	This allows predicates such as type_list_subsumes to check that
	the class constraints match.
	Note that `private_builtin:constraint' has no declaration, so
	a lookup in the type definition map will fail. That's OK, because
	type_to_type_id will fail on it, so it will be treated as a type
	variable by any code which doesn't manipulate types directly.
	Added polymorphism__typeclass_info_class_constraint to get the
	class_constraint from a typeclass_info's type. This isn't used yet.

	Also, fix a bug in extract_type_info: an entry in the typeinfo_var_map
	was being overwritten using an entry from a dummy typevarset. Actually
	the optimization to overwrite the location of the type_info after
	extracting it from a typeclass_info was wrong because the type_info
	won't be in that location in other branches.

compiler/higher_order.m:
	Rework the handling of type substitutions. Now the types of the
	called procedure are `inlined' into the calling procedure, rather
	than building up the types of the specialised version using the
	higher-order arguments. The advantage of this is that the code is
	a bit simpler and handles extra type_infos properly. The disadvantage
	is that the argument types for specialised versions may be more
	specific than they need to be, so in some cases more specialised
	versions will be created than before.
	Also, don't actually rebuild the higher-order terms in the specialised
	versions - just pass the terms through in case they are needed.
	Handle the extra typeinfos required for --typeinfo-liveness.
	Specialize calls to unify/2, index/2 and compare/3.
	Specialize class_method_calls.
	Specialize calls to the predicates in private_builtin.m which
	manipulate typeclass_infos.

compiler/type_util.m:
	type_to_type_id now fails on the dummy `constraint' type.
	Remove typeinfos for non-variable types from the typeinfo_varmap
	after inlining and higher-order specialisation.

compiler/inlining.m:
	Factor out some common code to handle type substitutions
	for use by higher_order.m.

compiler/hlds_pred.m:
	Return the list of extra type_info variables added to the
	argument list.

compiler/goal_util.m:
	Take a set of non-locals as an argument to
	goal_util__extra_nonlocal_typeinfos rather than extracting
	them from a goal.

compiler/special_pred.m:
	Handle unmangled unify/compare/index in special_pred_get_type.

compiler/base_type_layout.m:
	Don't generate references to the typeinfo for
	`private_builtin:constraint' - it doesn't exist.

compiler/unused_args.m:
	Don't barf on specialised unification predicate names.

compiler/options.m:
	Added options:
	`--type-specialization' (default off).
	`--higher-order-size-limit' - restrict the size of specialized
		versions produced by higher_order.m.
	`--disable-opt-for-trace' (default on) - where possible don't
		change the options to make the trace match the source code.

compiler/handle_options.m:
	Don't disable higher_order.m when --typeinfo-liveness is set.
	Handle `--disable-opt-for-trace'.

compiler/hlds_data.m:
compiler/*.m:
	Add the instance number to `base_typeclass_info_const' cons_ids,
	so that higher_order.m can easily index into the list of instances
	for a class to find the methods.

compiler/hlds_out.m:
	Use the correct varset when printing out the constraint proofs.
	Write the typeclass_info_varmap for each procedure.

compiler/mercury_to_mercury.m:
	Print type variables with variable numbers.

library/private_builtin.m:
	Add the argument to the typeclass_info type to hold the representation
	of the constraint.

runtime/mercury_ho_call.c:
	Semidet and nondet class_method_calls where
	(0 < num_arg_typeclass_infos < 4) were aborting at runtime
	because arguments were being placed starting at r1 rather
	than at r(1 + num_arg_typeclass_infos).

doc/user_guide.texi
	Document the new options.

compiler/notes/compiler_design.html:
	Update the role of higher_order.m.

tests/hard_coded/typeclasses/extra_typeinfo.m:
	Test case for the mercury_ho_call.c bug and the polymorphism.m
	extract_typeinfo bug and for updating the typeclass_info_varmap
	for specialised versions.
1998-09-10 06:56:14 +00:00
David Jeffery
0d304892cd Remove a very suspicious looking application of a *variable* type
Estimated hours taken: 0.1

compiler/polymorphism.m:
        Remove a very suspicious looking application of a *variable* type
        mapping to a type with *type variables* in it. The code doesn't seem
        to have any purpose, and all the test cases still pass.
1998-08-26 04:38:16 +00:00
David Jeffery
579ed303be Fix the code which adds C code type-infos to only add type-infos for
Estimated hours taken: 1

compiler/polymorphism.m:
        Fix the code which adds C code type-infos to only add type-infos for
        *unconstrained* existentially typed tvars.
1998-08-23 08:40:34 +00:00
David Jeffery
695b1bf0a4 Fix a bug that was causing generated TypeClassInfo variables in C code
Estimated hours taken: 1

Fix a bug that was causing generated TypeClassInfo variables in C code
to be incorrectly generated.  Sometimes input variables would be used
as outputs, and vice versa.

compiler/polymorphism.m:
      Generate the names of the variables in the same order as their
      types and modes.
1998-08-22 14:02:11 +00:00
David Jeffery
db944b142a Back out a previous change which spits out progress messages during
Estimated hours taken: 0.1

compiler/polymorphism.m:
        Back out a previous change which spits out progress messages during
        polymorphism.m because it produces too much output.
1998-08-21 04:06:45 +00:00
David Jeffery
5a7e080da4 When adding C variables for the type_info variables to pragma_c_code,
Estimated hours taken: 1


compiler/polymorphism.m:

        When adding C variables for the type_info variables to pragma_c_code,
        do not add type-infos for those that are constrained, but instead add
        a variable for the typeclass-info.

        Also print out a per-pred progress message during polymorphism.
1998-08-20 12:00:38 +00:00
David Jeffery
4556cccae8 Remember the term__context of where we read an instance method from so that
Estimated hours taken: 2

Remember the term__context of where we read an instance method from so that
we can give more accurate error messages. Also (slightly) improve the text of
the error message for instance methods.

check_typeclass.m:
        Use the term__context of the instance method declaration as the
        term__context for the introduced pred.
hlds_out.m:
        If the pred is one introduced as an instance method, give a
        (slightly) better error message.
mercury_to_mercury.m:
        Ignore the term context.
module_qual.m:
        Pass along the term context.
prog_data.m:
        Add a term__context to the instance_method
prog_io_typeclass.m:
        Store the term__context in the instance_method
1998-08-04 06:44:27 +00:00
Tyson Dowd
0384629015 Remove some dead code.
Estimated hours taken: 1

Remove some dead code.

compiler/polymorphism.m:
	Remove polymorphism__get_special_proc_list as it isn't used.
1998-08-04 01:51:26 +00:00
Zoltan Somogyi
5186a647f6 Add a missing module name to a predicate call, which caused SICStus
Estimated hours taken: 0.1

compiler/polymorphism.m:
	Add a missing module name to a predicate call, which caused SICStus
	to barf.
1998-07-30 09:00:14 +00:00
Fergus Henderson
6455e041cb Merge in the changes from the existential types branch,
Estimated hours taken: 6
	(plus another 80 or so already recorded for
	my commits on the existential_types branch)

Merge in the changes from the existential types branch,
and make some modifications to address dgj's code review comments.

These changes add support for existentially quantified type variables
and type class constraints on functions and predicates.
(Existential data types, however, are not supported -- see below.)

Existentially quantified type variables are introduced with
an explicit `some [T]', e.g. `:- some [T] pred foo(T)'.
Existentially quantified type class constraints are introduced
with `&' instead of `<=', e.g. `:- some [T] (pred foo(T) & ord(T))'.

There's still several limitations:

0.  XXX It's not yet documented in the language reference manual.

1.  XXX It doesn't do any mode checking or mode reordering.
    If you write code that uses existentially typed procedures in the
    wrong order, then you'll get an internal error in polymorphism.m
    or in the code generator.  (Cases where a type_info has no
    producer at all are caught by the check for unbound type
    variables in post_typecheck.m.)

    To support this, we need to change things so that polymorphism.m
    gets invoked before mode checking.

2.  Using `in' modes on arguments of existential type won't work.
    If you try, you will get a compile error.

    It would be nice to extend things to allow this kind of
    "implied mode" for type_infos, where an existential type
    becomes a universal type if some value of that type is
    input.  Supporting this would require first fixing
    limitation 1 (described above) and then

3.  There's no support for `pragma c_code' for procedures
    with existential type class constraints.
    (In fact, there's not really any support for `pragma c_code'
    for procedures with universal type class constraints either --
    the C code has no way of getting access to the type class info.)

4.  XXX Taking the address of something which is existentially typed
    should be illegal, but we don't check this.

In addition, these changes in this batch make a start towards allowing
existentially typed data types.  The compiler now accepts existential
quantifiers and type class constraints on type definitions, and type
checks them accordingly (assuming all functor occurrences are
deconstructors, not constructors -- see limitation 2 above).  But
there's no special handling for them in polymorphism.m, so if you try
to use them, it will abort with an internal error.

The changes also includes fixes for a couple of bugs in typechecking
and polymorphism that I discovered while making the above changes,
and an improvement to the error reporting from typecheck.m in one case.
Those changes are listed separately below.

compiler/prog_data.m:
	Add a new type `class_constraints', which holds two different
	lists of constraints, namely the existentially quantified constraints
	and the universally quantified ones.
	Add a new field to the parse tree representation of pred and
	func declarations to hold a list of the existentially quantified
	type variables, and change the `list(class_constraint)' into
	`class_constraints' so that we can store existential constraints too.
	Add new fields to the `constructor' data type (formerly just a pair)
	to hold the existentially quantified type variables and
	type class constraints.

compiler/hlds_pred.m:
	Add several new fields to the pred_info:
	  - a list of the existentially quantified type variables;
	  - a list of the "HeadTypeParams": type variables which
	    cannot be bound by this predicate (i.e. those whose type_infos
	    come from this pred's caller or are returned from
	    other preds called by this one);
	  - and a list of unsatisfied type class constraints.
	Add a predicate pred_info_get_univ_quant_tvars to compute the
	universally quantified type variables.
	Change the pred constraints field from `list(class_constraint)'
	to `class_constraints' so that it can hold existential constraints too.

compiler/hlds_data.m:
	Add new fields to hlds_cons_defn to hold the existentially
	quantified type variables and type class constraints.

compiler/*.m:
	Minor changes to reflect the above-mentioned data structure
	changes in prog_data.m, hlds_pred.m, and hlds_data.m.

compiler/prog_io.m:
	Add code to parse the new constructs.

	Also rewrite the code for parsing purity specifiers,
	type quantifiers and type class constraints, using basically
	the method suggested by Peter Schachte: treat these as
	"declaration attributes", and have parse_decl strip off
	all the declaration attributes into a seperate list and
	then pass that list to process_decl, which for each different
	kind of declaration processes the attributes which are
	appropriate for that declaration and then calls check_no_attributes
	to ensure that there were no inappropriate attributes.

	The purpose of this rewrite was to allow it to handle the new
	constructs properly, and to avoid unnecessary code duplication.

compiler/mercury_to_mercury.m:
	Add code to pretty-print the new constructs.

compiler/make_hlds.m:
	Copy the new fields in the parse tree into the
	corresponding new fields in the pred_info.
	Add code to check for various misuses of quantifiers.

compiler/hlds_out.m:
	Print out the new fields in the pred_info (except the
	unsatisfied type class constraints -- if these are non-empty,
	post_typecheck.m will print them out in the error message).
	When printing out types, pass the AppendVarNums parameter down,
	so that HLDS dumps will distinguish between different type
	variables that have the same name.
	Delete hlds_out__write_constructor, since it was doing exactly
	the same thing as mercury__output_ctor.

compiler/typecheck.m:
	Lots of changes to handle existential types and existential
	type class constraints.

compiler/post_typecheck.m:
	When checking for unbound type variables,
	use the value of HeadTypeParams from the pred_info.

compiler/type_util.m:
	Delete `type_and_constraint_list_matches_exactly', since it was not
	used.  Add various `apply_variable_renaming_to_*' predicates for
	renaming constraints.

compiler/polymorphism.m:
	Lots of changes to handle existential types and existential
	type class constraints.
	Also some changes to make the code more maintainable:

compiler/prog_data.m:
compiler/hlds_goal.m:
compiler/mercury_to_mercury.m:
	Put curly braces around the definitions of 'some'/2 and '&'/2 functors
	in `:- type' definitions, to avoid them being misinterpreted as
	existential type constraints.

compiler/goal_util.m:
compiler/polymorphism.m:
compiler/hlds_pred.m:
compiler/lambda.m:
	Include type_infos for existentially quantified type variables
	and type_class_infos for existential constraints
	in the set of extra variables computed by
	goal_util__extra_type_info_vars.

compiler/inlining.m:
	Change inlining__do_goal to handle inlining of calls to
	existentially typed predicates -- for them, instead of not
	binding any type variables at all in the caller, it allows the
	call to bind any type variables in the caller except for those
	that are universally quantified.

compiler/inlining.m:
compiler/deforest.m:
	Call pred_info_get_univ_quant_tvars and pass the
	result to inlining__do_inline_goal.

tests/hard_coded/Mmakefile:
tests/hard_coded/existential_types_test.{m,exp}:
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/existential_type_classes.{m,exp}:
	Test cases for the use of existential types and
	existential type class constraints.

----------

Improve an error message.

compiler/typecheck.m:
	Improve error reporting by checking type class constraints for
	satisfiability as we go and thus reporting unsatisfiable constraints
	as soon as possible, rather than only at the end of the clause.
	Previously we already did that for the case of ground constraints,
	but they are not the only unsatsfiable constraints: constraints
	on head type params (type variables which cannot be bound) are
	also unsatisfiable if they can't be eliminated straight away
	by context reduction.

tests/invalid/Mmakefile:
tests/invalid/typeclass_test_7.{m,err_exp}:
	Regression test for the above change.

----------

Avoid problems where type inference was reporting some
spurious errors for predicates using type classes,
because the check for unsatisfied type class constraints
was being done before the final pass of type inference
had finished.

compiler/hlds_pred.m:
	Add new field to the pred_info containing the unproven
	type class constraints.

compiler/typecheck.m:
	When inferring type class constraints, make sure that before
	we save the results back in the pred_info, we restrict the
	constraints to the head type variables.  Constraints
	on other type variables should be treated as
	unsatisfied constraints.

	Don't check for unsatisfied type class constraints at the
	end of each pass; instead, just save the unproven type class
	constraints in the pred_info.

compiler/post_typecheck.m:
	Check for unsatisfied type class constraints, using
	the new field in the pred_info.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/inference_test_2.{m,exp}:
tests/invalid/Mmakefile:
tests/invalid/typeclass_test_8.{m,err_exp}:
	Add regression tests for this change.

----------

Fix a bug with the computation of the non-locals for
predicates with more than one constraint on the same type variable --
it was only including one of the type-class-infos, rather than all of them.

compiler/goal_util.m:
	Change `goal_util__extra_nonlocal_typeinfos' so that it gets
	passed the TypeClassInfoVarMap and uses this to include all
	the appropriate typeclass infos in the extra nonlocals.

compiler/hlds_pred.m:
compiler/lambda.m:
compiler/polymorphism.m:
	Pass the TypeClassInfoVarMap to `goal_util__extra_nonlocal_typeinfos'.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/lambda_multi_constraint_same_tvar.{m,exp}:
	Regression test for the above-mentioned bug.
1998-07-08 20:59:50 +00:00
David Jeffery
cd354aabe9 When building the type-infos to be packaged inside a typeclass-info,
compiler/polymorphism.m:
	When building the type-infos to be packaged inside a typeclass-info,
	apply the variable type bindings first.

tests/valid/instance_unconstrained_tvar.m:
	Test case for this.
tests/valid/Mmakefile:
	Turn this test on. Also turn another test on which I mistakenly
	turned off in my previous commit (because the test was failing).
1998-06-19 00:42:37 +00:00
David Jeffery
2d391a8206 Fix a bug where polymorphism.m was erroneously applying a type substition
Estimated hours taken: 4

Fix a bug where polymorphism.m was erroneously applying a type substition
recursively, causing an infinite loop in certain situations.

compiler/polymorphism.m:
        Change a call to term__apply_rec_substitution_to_list into
        term__apply_substitution_to_list.

        Also put the goals to initialise the superclass type-infos *before*
        the construction unification for the sub-class.
1998-06-18 03:51:04 +00:00
Thomas Conway
a70b59e83c Add a test to find the number of words needed to represent a
configure.in:
        Add a test to find the number of words needed to represent a
        synchronization term.

boehm_gc/gc.h:
        fix a declaration by replacing the args () with (void).
boehm_gc/solaris_pthreads.c:
        add a missing include
        check the return values of pthread calls.

compiler/*.m:
        Add handling for the new HLDS goal type par_conj.
        Add handling for the four new LLDS instructions:
                init_sync_term
                fork
                join_and_terminate
                join_and_continue

compiler/code_info.m:
        add a new alternative for slot_contents - sync_term.

compiler/handle_options.m:
        add .par as part of the grade

compiler/hlds_goal.m:
        add the new goal type par_conj.

compiler/instmap.m:
        add instmap__unify which takes a list of instmaps
                and abstractly unifies them.
        add unify_instmap_delta which tajes two instmap deltas
                and abstractly unifies them.

compiler/llds.m:
        add the new llds instructions.

compiler/mode_info.m:
        add par_conj as a lock reason.

library/Makefile:
        work around a bug in the solaris version pthread.h

library/benchmarking.m:
        reference the stack zones from the engine structure
        rather than from global variables.

library/{nc,sp}_builtin.nl:
        add an op declaration for &.

library/std_util.m:
        change references to global variables to references inside
        the engine structure.

runtime/Mmakefile:
        add mercury_thread.{c,h}
        add THREADLIBS to the libraries

runtime/*.{c,h}
        Remove some old junk from the previous processes/shrd-mem
        changes that found their way into the repository.
        Add MR_ prefixes to lots of names.

runtime/mercury_context.c:
        Add init_thread_stuff for creating and initializing a
        context structure for the current thread.

runtime/mercury_context.h:
        add a field to the mercury context which stores the thread id
        of the thread where this context originated.
        add various macros for implementing the new llds instructions.

runtime/mercury_engine.c:
        initialize the engine structure, rather than a bunch of globals.

runtime/mercury_engine.h:
        declare the mercury_engine structure.

runtime/mercury_regorder.h:
        if MR_THREAD_SAFE, and there is at least one global register
        then use mr0 as a pointer to the mercury engine structure.

scripts/init_grade_options.sh-subr
        add thread_safe

scripts/mgnuc.in
        add THREAD_OPTS

scripts/ml.in:
        add THREAD_LIBS
1998-06-09 02:16:31 +00:00