Commit Graph

10 Commits

Author SHA1 Message Date
Zoltan Somogyi
43fbf4b956 A step towards RTTI in Mercury.
Estimated hours taken: 40
Branches: main

A step towards RTTI in Mercury.

This step redefines the representation of pseudo-typeinfos inside the compiler
to be identical to the representation we will need for efficient interpretation
of RTTI data structures in Mercury. Later steps will do likewise for
typectorinfos. In the end, we will have two implementations of RTTI:
the current low-level, very efficient one written in C, which will be used
by the C backends (both LLDS and MLDS), and a new, higher-level one
which will use Mercury data structures and Mercury predicates for
interpretation (along the lines of library/rtti_implementation.m)
for the Java and IL backends.

A large part of this change concerns the fact that pseudo-typeinfos can now
contain typeinfos as well as other pseudo-typeinfos, and they do in the
frequent case that the type of an argument is ground. Given that typeinfos
are just special cases of pseudo-typeinfos, the code for handling the two
types is usually similar, with common code factored out when relevant.

In the process of redesigning the data structures concerning (pseudo-)
typeinfos, I also fixed an old naming scheme that has become misleading.
The representation of a (pseudo-) typeinfo depends on whether the principal
type constructor is fixed arity or not. We used to denote this distinction
with the phrases first-order vs higher-order, since at first the only variable
arity type constructors were pred and func. However, this hasn't been true
since we added tuples. I have changed the naming scheme to be fixed-arity vs
variable-arity.

compiler/rtti.m:
	Add new, purely Mercury data structures for representing typeinfos
	and pseudo-typeinfos, designed both for efficient interpretation
	and as a source for the generation of static data structures in C.

compiler/pseudo_type_info.m:
	Delete the type definitions here, since they are superseded by the new
	definitions in rtti.m.

	Add predicates for constructing typeinfos as well as pseudo-typeinfos,
	since now we need those too.

	Conform to the changed data structures for (pseudo-) typeinfos.

compiler/ll_pseudo_type_info.m:
compiler/ml_closure_gen.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/opt_debug.m:
compiler/type_ctor_info.m:
	Conform to the changed data structures for (pseudo-) typeinfos.

compiler/mlds.m:
	Since the MLDS now refers to type_infos, add their type
	(mlds__type_info_type) to the list of types the MLDS knows about.

compiler/ml_code_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Handle mlds__type_info_type.

compiler/mlds_to_gcc.m:
	Conform to the changed data structures for (pseudo-) typeinfos,
	and handle mlds__type_info_type.

runtime/mercury_bootstrap.h:
	Override the compiler-generated names of the type_ctor_infos of the
	variable arity type constructors. The MLDS backend requires these
	to be module qualified; the LLDS backend requires them to be
	unqualified. This is a problem because the same code now generates
	the compiler's internal representation of pseudo-typeinfos for both
	backends.

	The temporary solution is to have the compiler generate these names
	module qualified, and have these macros convert them to the unqualified
	form. (The long term solution should be to always module qualify
	everything, but doing that is for another change.)

runtime/mercury_type_info.h:
	Change the naming scheme from first order vs higher order to fixed
	arity vs variable arity.

library/construct.m:
library/deconstruct.m:
runtime/mercury.c:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_make_type_info_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_desc.c:
runtime/mercury_type_info.c:
runtime/mercury_unify_compare_body.h:
	Conform to the new naming scheme.

runtime/mercury.h:
	Conform to the new naming scheme.

	Declare fixed and variable arity types for typeinfos as well as
	pseudo-typeinfos, since pseudo-typeinfos can now refer to typeinfos.
2002-04-12 01:24:25 +00:00
Zoltan Somogyi
62c3375f5d Fix the RTTI of type_descs and type_ctor_descs.
Estimated hours taken: 40
Branches: main

Fix the RTTI of type_descs and type_ctor_descs. Make comparisons between
type_ctor_descs and type_ctor_infos (and therefore between type_descs and
type_infos) more predictable and consistent across backends by basing them
on programmer-visible attributes instead of accident of location in the
executable.

runtime/mercury_type_desc.[ch]:
	Implement unification and comparison functions for type_ctor_descs.
	(The unification and comparison functions for type_infos also double
	as the unification and comparison functions for type_descs.)

	Make the comparison function work on the module name, type name and
	arity instead of the address of the type_ctor_info structure. This
	ensures consistency across back ends.

	Add some useful macros.

runtime/mercury_type_info.[ch]:
	Make the comparison function on type_ctor_infos also work on module
	name, type name and arity. Since this makes comparison slower, add
	specialized unification functions for type_infos and type_ctor_infos.

runtime/mercury_type_info.h:
runtime/mercury_mcpp.{h,cpp}:
runtime/mercury.h:
library/private_builtin.m:
library/rtti_implementation.m:
java/runtime/TypeCtorRep.java:
compiler/mlds_to_gcc.m:
	Add type_ctor_reps for type_descs and type_ctor_descs. Type_ctor_descs
	definitely need it, since their representation is very low level and
	not shared with anything else. Type_descs could use the type_ctor_rep
	of type_infos, since type_descs and type_infos share the same
	representation at the moment. However, we add a new one because
	profiling cares about the conceptual distinction between type_infos
	and type_descs.

library/type_desc.m:
	Delete the Mercury "definition" of type_desc, because it is misleading.
	Implement it as a builtin type.

runtime/mercury.[ch]:
	Implement type_ctor_desc as a builtin type.

	Add missing implementations of unify/compare on type_ctor_infos.

runtime/mercury_deconstruct.c:
runtime/mercury_ml_expand_body.h:
	Implement deconstruction for type_descs and type_ctor_descs.

runtime/mercury_ho_call.c:
runtime/mercury_unify_compare_body.h:
	Implement unify and compare for type_descs and type_ctor_descs.

	Implement unify for type_infos, type_ctor_infos, type_descs and
	type_ctor_descs by calling the relevant unification function,
	not the relevant comparison function, since the unification
	function will be faster.

runtime/mercury_deep_copy_body.h:
runtime/mercury_construct.c:
runtime/mercury_tabling.c:
	Minor changes to handle type_descs and type_ctor_descs.

trace/mercury_trace_vars.c:
	Enable the printing of type_descs and type_ctor_descs.

tests/debugger/type_desc_test.{m,inp,exp,exp2}:
	New test case to check the printing of type_descs and type_ctor_descs.

tests/debugger/Mmakefile:
	Enable the new test case.

tests/hard_coded/type_ctor_desc_manip.{m,exp}:
	New test case to check the deconstruction and comparison of type_descs
	and (especially) type_ctor_descs. Before this change, we got different
	results for comparisons of type_ctor_descs, results that were
	inconsistent with the results of comparisons of the type_descs
	that the type_ctor_descs were derived from.

tests/hard_coded/Mmakefile:
	Enable the new test case.
2002-03-27 05:18:58 +00:00
Zoltan Somogyi
7570fac833 Some of fjh's review comments on my change to enable the deconstruction and
Estimated hours taken: 3
Branches: main

Some of fjh's review comments on my change to enable the deconstruction and
printing of igher order terms arrived after I committed that change. This diff
addresses those comments.

library/deconstruct.m:
	Specify what happens with include_details_cc.


runtime/mercury_deconstruct.c:
	Add a second argument to MR_expand_type_name that specifies whether
	the name of the type specified by the first argument should be wrapped
	in <<>> or not.

runtime/mercury_ml_expand_body.h:
 	Handle type_ctor_infos by returning the type name (without <<>>) as
	a zero-arity functor.

runtime/mercury_type_info.[ch]:
	Delete the code for expanding out type_ctor_info "equivalences", since
	as Fergus pointed out the concepts doesn't make sense.

trace/mercury_trace_internal.c:
	When the user turns the printing of optional values off or on,
	make that change take effect immediately.

tests/debugger/queens.{inp,exp*}:
	Test the immediate nature of the print_optionals command.

NEWS:
	Announce the print_optionals command.
2002-03-12 03:40:42 +00:00
Fergus Henderson
c4c11ef5ac Fix incorrect handling of transient registers:
Estimated hours taken: 4
Branches: main

runtime/mercury_ml_expand_body.h:
	Fix incorrect handling of transient registers:
	- Delete the incorrect wrapping of
	  MR_restore_transient_hp()/MR_save_transient_hp()
	  around calls to the FUNCTION MR_expand_type_name(),
	  which expects the heap pointer to be saved (if transient);
	  the hp is already saved (if transient) before the call,
	  and trying to restore it immediately after a call to
	  a C function has returned will just fill it with garbage.
	- Wrap MR_restore_transient_hp()/MR_save_transient_hp()
	  around calls to the MACRO MR_make_aligned_string,
	  because it expects the hp register to be valid,
	  and because it can allocate heap.

runtime/mercury_ml_expand_body.h:
runtime/mercury_deconstruct.c:
	Add default cases that call MR_fatal_error() to a couple of switch
	statements, to supress gcc warnings about uninitialized variables.
2002-02-22 01:14:18 +00:00
Simon Taylor
b7c4a317e9 Add MR_ prefixes to the remaining non-prefixed symbols.
Estimated hours taken: 4
Branches: main

Add MR_ prefixes to the remaining non-prefixed symbols.

This change will require all workspaces to be updated
The compiler will start generating references to MR_TRUE,
MR_bool, etc., which are not defined in the old runtime
header files.

runtime/mercury_std.h:
	Add MR_ prefixes to bool, TRUE, FALSE, max, min,
	streq, strdiff, strtest, strntest, strneq, strndiff,
	strntest, NO_RETURN.

	Delete a commented out definition of `reg'.

runtime/mercury_tags.h:
	Add an MR_ prefix to TAGBITS.

configure.in:
runtime/mercury_goto.h:
runtime/machdeps/i386_regs.h/mercury_goto.h:
	Add an MR_ prefix to PIC.

runtime/mercury_conf_param.h:
	Allow non-prefixed PIC and HIGHTAGS to be defined on
	the command line.

runtime/mercury_bootstrap.h:
	Add backwards compatibility definitions.

RESERVED_MACRO_NAMES:
	Remove the renamed macros.

compiler/export.m:
compiler/ml_code_gen.m:
	Use MR_bool rather than MR_Bool (MR_Bool is
	meant to be for references to the Mercury type
	bool__bool).

runtime/mercury_types.h:
	Add a comment the MR_Bool is for references to
	bool__bool.

*/*.c:
*/*.h:
*/*.m:
	Add MR_ prefixes.
2002-02-18 07:01:33 +00:00
Zoltan Somogyi
fcccbd166f Reorganize deconstruct.m so that each predicate that deconstructs terms has
Estimated hours taken: 12
Branches: main

Reorganize deconstruct.m so that each predicate that deconstructs terms has
three variants:

- One that aborts when attempting to deconstruct non-canonical terms.

- One that succeeds when attempting to deconstruct a term of a non-canonical
  type, but returns a constant such as "<<noncanonical>>" for such
  deconstructions. It still aborts when deconstructing a noncanonical term
  of an ordinarily canonical type, which can happen with HAL if the term
  is currently a variable.

- One that succeeds when attempting to deconstruct non-canonical terms of both
  kinds, but whose determinism requires its caller to be in a committed choice
  context.

Each of the predicates function, arg, named_arg, deconstruct and
limited_deconstruct now has an extra argument that selects one of the three
variants above. Each of these predicates now has three modes, one for each
value of this argument. The separate predicates with _cc at the ends of their
names are now superseded by one of these modes.

At the same time, I also eliminated the distinction between arg and argument.
Arg used to check if the returned argument was of the expected type, and fail
if it wasn't, while argument used to return a univ. The new arg now returns
a value of an existential type, which the caller can now typecheck or put
into a univ as it pleases.

The descriptions of the changes:

library/deconstruct.m:
	Implement the changes discussed above. Work around a bug by making
	the foreign_procs return a univ from which we later extract the value;
	this inefficiency should be fixed later, when the typechecker has been
	fixed to allow different clauses to return existentially typed values.

library/std_util.m:
	Reimplement the forwarding predicates that call deconstruct.m in terms
	of its new interface.

library/io.m:
	Make use of the new functionality in deconstruct.m to offer versions
	of io__print and io__write that allow the user to choose how to print
	noncanonical terms.

library/private_builtin.m:
	Export the `sorry' predicate for use in deconstruct.m and elsewhere.

runtime/mercury_deconstruct.[ch]:
runtime/mercury_ml_expand_body.h:
runtime/mercury_ml_arg_body.h:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
	Implement the new functionality.

library/store.m:
extras/trailed_update/tr_store.m:
	Conform to the new interfaces of some functions in the updated files
	in the runtime.

tests/debugger/polymorphic_output.exp*:
	Update for an updated error message.

tests/hard_coded/deconstruct_arg.{m,exp*}:
	Update the test case to test the committed choice versions of the
	deconstruction predicates as well as the usual versions. (The aborting
	versions cannot all be tested in a single test case.)
2002-02-04 05:23:10 +00:00
Zoltan Somogyi
2b559ad054 Move the RTTI-related parts of std_util.m to three new modules in the standard
Estimated hours taken: 8
Branches: main

Move the RTTI-related parts of std_util.m to three new modules in the standard
library, and (in the case of embedded C code) to new modules in the runtime.
The main reason for this is to allow a reorganization of some of the
RTTi-related functionality without breaking backward compatibility. However,
the new arrangement should also be easier to maintain.

Use a separate type_ctor_rep for functions, to distinguish them from predicates
for RTTI code. (At one point, I thought this could avoid the need for the
change to the initialization files mentioned below. It can't, but it is a good
idea in any case.)

library/std_util.m:
	Remove the functionality moved to the new modules, and replace them
	with type equivalences and forwarding code. There are no changes in
	the meanings of the user-visible predicates, with two exceptions.

	- First, the true, equivalence-expanded names of what used to be
	  std_util:type_desc and std_util:type_ctor_desc are now
	  type_desc:type_desc and type_desc: type_ctor_desc.
	- Second, deconstructing a function term now yields
	  "<<function>>" instead of "<<predicate>>".

	The intention is that the RTTI predicates in std_util.m will continue
	to work in a backwards-compatible manner for the near future, i.e. as
	the new modules are updated, the code in std_util will be updated to
	maintain the same functionality, modulo improvements such as avoiding
	unwanted exceptions. When the RTTI functionality in the other modules
	has stabilised, the RTTI predicates in std_util.m should be marked
	obsolete.

	The exported but non-documented functionality of std_util has been
	moved to one of the new modules without forwarding code, with one
	of the moved predicates being turned into the function it should have
	been in the first place.

library/construct.m:
library/deconstruct.m:
library/type_desc.m:
	Three new modules for the code moved from std_util.m.

library/library.m:
compiler/modules.m:
	Record the names of the three new library modules.

runtime/mercury.[ch]:
compiler/mlds_to_il.m:
	Record that type_desc is now in type_desc.m, not std_util.m.

compiler/static_term.m:
	Import the deconstruct module, since we are using its undocumented
	facilities.

runtime/Mmakefile:
	Mention the two new modules.

runtime/mercury_construct.[ch]:
runtime/mercury_type_desc.[ch]:
	Two new modules holding the C functions that used to be in foreign_code
	in std_util, now using MR_ instead of ML_ prefixes, and being more
	consistent about indentation.

runtime/mercury_type_info.h:
	Add a new type_ctor_rep for functions, separate from predicates.
	(It reuses the EQUIV_VAR type_ctor_rep, which hasn't been used
	in ages.)

	Use type_ctor_reps to distinguish between the type_ctor_infos of
	pred/0 and func/0. However, to create higher order typeinfos, we
	still need to know the addresses of the type_ctor_infos for
	pred/0 and func/0, and we still need to know the address of the
	type_ctor_info for tuples to create typeinfos for tuples. Since
	these three type_ctor_infos are defined in the library,
	we cannot access them directly from the runtime. We therefore need
	to access them indirectly in the usual manner, via address_of
	variables initialized by mkinit-generated code.

library/builtin.m:
library/private_builtin.m:
library/rtti_implementation.m:
runtime/mercury.c:
runtime/mercury_mcpp.{h,cpp}:
java/TypeCtorRep.java:
	Updates to accommondate the new function type_ctor_rep.

runtime/mercury_type_info.[ch]:
	Add some functions from foreign_code in std_util that fit in best here.

runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.h:
runtime/mercury_unify_compare_body.h:
	Delete the code for handling EQUIV_VAR, and add code for handling
	functions.

runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
	Add three variables holding the address of the type_ctor_infos
	representing functions, predicates and tuples.

util/mkinit.c:
	Fill in these three variables.

tests/general/accumulator/construct.{m,exp}:
tests/general/accumulator/deconstruct.{m,exp}:
tests/hard_coded/construct.{m,exp}:
	Rename these tests by adding a _test at the ends of their names,
	in order to avoid collisions with the names of the new standard library
	modules. The test cases have not changed, with the exception of the :-
	module declaration of course.

tests/general/accumulator/Mmakefile:
tests/general/accumulator/INTRODUCED:
tests/hard_coded/Mmakefile:
	Record the name changes.

tests/hard_coded/existential_float.exp:
	Updated the expected output to reflect that deconstructions now print
	"<<function>>" instead of "<<predicate>>" when appropriate.

tests/hard_coded/higher_order_type_manip.exp:
	Updated the expected output to reflect the new name of what used to be
	std_util:type_desc.

trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	#include type_desc.h instead of std_util.h, since the C functions
	we want to call are now defined there.

trace/mercury_trace_vars.c:
	Update to account for the movement of type_desc from std_util to
	type_desc, and ensure that we don't refer to any type_ctor_infos
	in MLDS grades.
2002-01-30 05:09:13 +00:00
Zoltan Somogyi
b5c571c500 This is the first half of a change that removes redundant fields from
Estimated hours taken: 12
Branches: main

This is the first half of a change that removes redundant fields from
type_ctor_info structures.

configure.in:
	Do not require an exact match on the RTTI version number.

runtime/mercury_type_info.h:
	Update the RTTI version number.

	Add the new definition of type_ctor_infos.

	Add prefixes to the fields in type_ctor_infos that did not already have
	them.

	Provide macros to access the fields in the changed part of
	type_ctor_infos in a way that works with both the old and new
	type_ctor_info structures.

	Move some stuff so that macros that logically belong together are next
	to each other.

runtime/mercury_mcpp.h:
	Update the RTTI version number and the macros for defining
	type_ctor_infos.

library/rtti_implementation.m:
	Update the mechanism for access to type_ctor_info fields.

	Add prefixes to field names and use RTTI-version-independent macros
	as necessary.

compiler/hlds_module.m:
compiler/rtti.m:
	Delete obsolete fields from the terms from which type_ctor_info
	structures are derived.

compiler/dead_proc_elim.m:
	Minor changes to conform to this change in data structure.

compiler/type_ctor_info.m:
	Minor changes to conform to this change in data structure.
	Update the RTTI version number.

compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
	Output the new type_ctor_info structure.

compiler/llds_out.m:
compiler/mlds_to_c.m:
	Emit a #define to select the new type_ctor_info structure.

library/std_util.m:
runtime/mercury.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
runtime/mercury_type_tables.c:
runtime/mercury_unify_compare_body.h:
tests/hard_coded/type_tables.m:
trace/mercury_trace.c:
	Add prefixes to field names and use RTTI-version-independent macros
	as necessary.
2002-01-25 08:23:39 +00:00
Zoltan Somogyi
0ddb8857b5 This is the second half of a change that reduces the size of type_ctor_info
Estimated hours taken: 8
Branches: main

This is the second half of a change that reduces the size of type_ctor_info
structures, and moves the version number to the start (immediately after the
arity) to make future changes easier.

This is a bootstrapping change; you will need to recompile all your files
after it is installed. The bootstrap tag is bootstrap_20020111_grade_v4.

configure.in:
	Require the use of a compiler that implements the first half of this
	change.

runtime/mercury_bootstrap.h:
	Add synonyms for use until this change is installed on all machines.

runtime/mercury_deconstruct.c:
	Make some code RTTI-version independent.

runtime/mercury_grade.h:
	Increment the grade version number to prevent linking of code of that
	doesn't understand the new type_ctor_info structure with code that
	requires it.

runtime/mercury_type_info.h:
	Delete the old versions of the type_ctor_info structure and update
	the appropriate macros.
2002-01-11 04:43:32 +00:00
Zoltan Somogyi
ce62be8669 Add committed choice versions of the functions and predicates that deconstruct
Estimated hours taken: 12
Branches: main

Add committed choice versions of the functions and predicates that deconstruct
terms. These versions succeed even if the the term being deconstructed is of a
non-canonical type.

NEWS:
	Mention the new procedures.

library/std_util.m:
	Add the following procedures: functor_cc, argument_cc, det_argument_cc,
	named_argument_cc, det_named_argument_cc, deconstruct_cc and
	limited_deconstruct_cc.

	To avoid code duplication, factor out the code common to several
	procedures and put it into three new files in the runtime directory,
	mercury_ml_{fuctor,arg,deconstruct__body.h.

	Add arguments to the various expansion functions to control what they
	should do for non-canonical types. Move them to mercury_deconstruct.c
	in the runtime directory to make it easier to access them from other
	places.

	Fix some bugs in the code for det_arg and family in the computation
	of abort messages.

library/store.m:
extras/trailed_update/tr_store.m:
trace/mercury_trace_vars.c:
	Adjust the references to the expansion functions.

runtime/mercury_deconstruct.[ch]:
	A new module to contain the expansion functions.

runtime/mercury_ml_arg_body.h:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
	New files to contain the bodies of the std_util procedures for
	deconstructing terms.

runtime/mercury_deconstruct_macros.h:
	A new header file for macros used in several places.

library/Mmakefile:
runtime/Mmakefile:
	Add the new files to the required lists.
2002-01-09 06:41:35 +00:00