Commit Graph

76 Commits

Author SHA1 Message Date
Zoltan Somogyi
b39a3d855f This diff makes hlds_module.m and many callers of its predicates easier to read
Estimated hours taken: 6
Branches: main

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

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

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

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

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

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

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

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

	Change the fold predicates to use state variable notation.

NEWS:
	Mention the new library functions.
2003-10-31 03:27:39 +00:00
Zoltan Somogyi
8693e293a2 This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4
Branches: main

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

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

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

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

	Standardize indentation.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Switch the predicate involved to use state var syntax.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Add term_size_profiling_builtin.increase_size as a
	no_type_info_builtin.

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

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

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

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

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

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

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

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

	Fix formatting of foreign_procs.

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

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

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

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

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

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

	Document the incompatibility of MR_HIGHTAGS and the Boehm collector.

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

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

	Fix a bug caused by a missing backslash.

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

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

	Call new diagnostic macros that can help debug heap allocations.

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

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

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

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

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

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

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

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

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

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

	Detect incompatibilities between high level code and profiling.

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

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

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

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

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

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

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

runtime/Mmakefile:
	Mention the new files.

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

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

runtime/mercury_tabling.h:
	Delete some unused macros.

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

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

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

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

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

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

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

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

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

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

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

	Do the same for the deep profiling builtin module.

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

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

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

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

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

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

tests/valid/Mmakefile:
	Disable the IL tests in term size profiling grades, since the term size
	profiling primitives haven't been (and probably won't be) implemented
	for the MLDS backends, and handle_options causes a compiler abort
	for grades that combine term size profiling and any one of IL, Java
	and high level C.
2003-10-20 07:29:59 +00:00
Fergus Henderson
9656086353 Implement accurate GC for type class methods.
Estimated hours taken: 24
Branches: main

Implement accurate GC for type class methods.
Accurate GC now supports the whole Mercury language.

compiler/ml_closure_gen.m:
	Generate GC tracing code for the type class method instance
	wrapper functions whose addresses get stored in typeclass_infos.
	This code generates a closure layout for the method instance
	procedure, and then calls MR_materialize_closure_params(),
	passing it the typeclass_info and the closure layout.

runtime/mercury_layout_util.h:
runtime/mercury_layout_util.c:
	Add new routine MR_materialize_typeclass_info_params(), for use
	by the code generated by ml_closure_gen.m.
	This is similar to MR_materialize_closure_params() except that
	it works on a typeclass_info rather than an MR_Closure.

compiler/ml_code_util.m:
	Change ml_bump_function_labels so that it also bumps the constant
	sequence number, and rename it as ml_bump_counters.  This is needed
	to avoid clashes between different local closure_layout constants
	after they get hoisted to the top level by ml_elim_nested.m.

compiler/rtti_to_mlds.m:
	Update to reflect the changed interface to ml_gen_closure_wrapper
	and ml_code_util.m.

compiler/ml_elim_nested.m:
	Update the accurate GC TODO list.

compiler/options.m:
doc/user_guide.texi:
	Document that accurate GC is now supported.

NEWS:
	Mention that we now support accurate GC.
2003-09-25 07:56:47 +00:00
Zoltan Somogyi
599ef915d9 Instead of being relied on all over the place, centralize the compiler's
Estimated hours taken: 16
Branches: main

Instead of being relied on all over the place, centralize the compiler's
knowledge of the names of unify, compare and index predicates in one place,
special_pred.m. This should make it easy to change the naming scheme once
we switch over to compiler-generated type_ctor_infos for builtin types,
which will eliminate the runtime system's knowledge of the naming scheme.

compiler/hlds_pred.m:
	Add a field to pred_infos that says whether the predicate is a unify,
	compare or index predicate, and if so, for which type constructor.
	Code that used to test the predicate's name for __Unify__ etc now
	tests this field instead. Similarly the code that used to employ
	devious tricks to find out the type the unify/compare/index predicate
	is for.

compiler/rtti.m:
	Include this field in rtti_proc_labels as well as pred_infos.

compiler/make_hlds.m:
	Fill in this field as appropriate.

compiler/proc_label.m:
	Replace the predicate name with special_pred_id in the proc_labels
	of unify, index and compare preds.

compiler/special_pred.m:
	Narrow the interface to prevent reliance on the naming scheme
	for compiler-generated unify, compare and index predicates,
	except when absolutely necessary, i.e. when creating names for
	them.

	Narrow the mechanism required to reverse-engineer the type constructor
	a unify/compare/index predicate is for from the types to the
	functionality required by higher_order.m.

compiler/code_gen.m:
compiler/det_report.m:
compiler/higher_order.m:
compiler/intermod.m:
compiler/layout_out.m:
compiler/magic_util.m:
compiler/ml_code_util.m:
compiler/name_mangle.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/optimize.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/proc_label.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/simplify.m:
compiler/termination.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unused_args.m:
	Update code and comments to conform to the changes above.

compiler/hlds_out.m:
	Don't refer to the 'type' that a unify, compare or index predicate
	is for; refer to the type *constructor*.

compiler/mlds_to_java.m:
	Delete an unused predicate.

tests/invalid/purity/purity.err_exp:
	Update this expected output for the change in hlds_out.m.
2003-05-27 05:57:30 +00:00
Fergus Henderson
8e9c813e37 Various fixes to make the Java back-end work better.
Estimated hours taken: 24
Branches: main

Various fixes to make the Java back-end work better.

compiler/ml_code_gen.m:
	Make sure that no module in the generated MLDS
	tries to import itself.

	Also, add some XXX comments about the handling of
	model_semi foreign_procs for Java and IL.

compiler/ml_code_util.m:
	Fix a bug with the handling of `top_unused' modes with `--det-copy-out'.

compiler/mlds_to_java.m:
	Add an XXX comment about the problem with type names clashing
	with constructor names.
	Add an XXX comment about ignoring `pragma foreign_import'
	and `pragma export' for Java.

	Fix the code so that we handle `foreign_decl' and `foreign_code'
	for Java properly -- previously, we were generating code for
	`foreign_decl' in the wrong place, and `foreign_code' was just
	ignored.

	Handle procedures defined as `external' by calling `extern_Foo',
	rather than generating a declaration with no body, because
	Java syntax doesn't allow that.

	Fix a bug where some names weren't getting mangled properly.

	Fix some bugs where it was not generating correct package
	names or module qualifiers for modules in the Mercury
	standard library.

library/Mmakefile:
	Add support for the `java' grade.
	This involved adding new targets `javas' and `classes',
	and making the main `library' target depend on these if
	the grade is `java'.

library/builtin.m:
	Add (stub) Java implementations of various builtins:
	- the type_ctor_infos for the builtin types int, string, character
	- builtin.unify/2 and builtin.compare/3
library/private_builtin.m:
	Add (stub) Java implementations of various builtins:
	- the type_ctor_info for private_builtin.type_info/1
	- builtin_compare_int/3, builtin_compare_string/3,
	  builtin_strcmp/3

library/math.m:
	- Fix a couple of bugs in the Mercury code for "log" and "log2".

library/std_util.m:
	Provide a Java implementation for cc_multi_equal/2.
	Avoid a compiler warning for the Mercury implementation
	of semidet_succeed and semidet_fail.

library/store.m:
	Rename the constructor for the `store/1' type,
	to work around a bug in the Java back-end.

library/string.m:
	Fix bugs in the Mercury implementation of string__contains_char
	and string__split.
	Provide a Java implementation of string__length.

library/type_desc.m:
	Provide Java implementations of type_of/1 and has_type/2.
	Provide (stub) implementations of the builtin types type_desc/0
	and type_ctor_desc/0.
2003-05-14 14:38:48 +00:00
Fergus Henderson
5689ca5307 Support `--gc accurate --nondet-copy-out'.
Estimated hours taken: 1
Branches: main

Support `--gc accurate --nondet-copy-out'.

compiler/ml_call_gen.m:
	Fix an XXX: change ml_gen_cont_params so that rather than
	aborting if accurate GC is enabled, we just document that it is
	the caller's responsibility to fill in the maybe_gc_trace_code
	if needed.

compiler/ml_call_gen.m:
compiler/ml_code_util.m:
	Document why it is safe to not bother filling in the
	maybe_gc_trace_code after calls to ml_gen_cont_params.

compiler/handle_options.m:
	Don't abort if --gc accurate and --nondet-copy-out are both enabled.

compiler/ml_elim_nested.m:
	Delete `--nondet-copy-out' from the TODO list for accurate GC.
2003-03-28 06:42:48 +00:00
Zoltan Somogyi
4954da84cc Reduce the dependence of the MLDS backend on the LLDS backend by moving
Estimated hours taken: 2
Branches: main

Reduce the dependence of the MLDS backend on the LLDS backend by moving
functionality dealing with proc_labels from the LLDS backend (code_util.m)
to a new module, proc_label.m, which is part of backend_libs.

compiler/code_util.m:
compiler/proc_label.m:
	Move a type and some code from code_util to the new module. Convert
	predicates to functions as relevant. (The old code was written before
	functions were available).

compiler/backend_libs.m:
	Add proc_label to the list of submodules.

compiler/rtti.m:
	Rename a function to avoid a name clash with a function in
	proc_label.m.

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

	Ensure that all imports of modules in the compiler directory are on
	lines of their own, to make CVS merges easier. Sort the imports.
2003-03-14 08:10:12 +00:00
Simon Taylor
9aeb2516ec Avoid dependencies on ll_backend.code_util in *hlds.*.
Estimated hours taken: 1
Branches: main

Avoid dependencies on ll_backend.code_util in *hlds.*.

compiler/code_util.m:
compiler/hlds_pred.m:
	Move the predicates to identify builtins into hlds_pred.m.

compiler/*.m:
	Update calls and remove unnecessary imports.
2003-02-28 06:40:43 +00:00
Simon Taylor
129f605d25 Fix bugs in the handling of purity in the optimization passes
Estimated hours taken: 8
Branches: main, release

Fix bugs in the handling of purity in the optimization passes
(in particular constraint propagation), which caused purity
annotations on goals to be lost. This caused
tests/tabling/unused_args to fail on earth.

compiler/hlds_goal.m:
	Make the version of goal_info_init called from
	the optimization passes take the purity as an
	argument. Previously, callers were constructing
	a goal_info then adding the purity, which was
	error prone.

compiler/hlds_goal.m:
compiler/purity.m:
	Move the predicates to deal with purity representation
	in hlds_goal_infos into hlds_goal.m. Rationale -
	goal_info_get_determinism is not in det_analysis.m,
	goal_info_get_nonlocals is not in quantification.m, etc.
	This makes it easier to make the purity setting code
	efficient.

	Don't allocate memory in add_goal_info_purity_feature
	if the call doesn't change the purity.

compiler/*.m:
	Pass the extra argument to goal_info_init.

compiler/polymorphism.m:
	Remove a duplicate definition of
	hlds_goal__make_int_const_construction.

compiler/magic.m:
	Remove some unused code.

tests/hard_coded/purity/Mmakefile:
tests/hard_coded/purity/Mercury.options:
tests/hard_coded/purity/purity_opt.{m,exp}:
	Test case.
2003-02-28 00:21:42 +00:00
Fergus Henderson
ddb677279c Ensure that in MLDS grades, arguments with arg_mode `top_unused' do not
Estimated hours taken: 2
Branches: main

Ensure that in MLDS grades, arguments with arg_mode `top_unused' do not
get passed.

Previously, different parts of the compiler had different and inconsistent
ideas about if/how they should get passed, which caused problems,
including an internal error for tests/hard_coded/foreign_type2.m in grade
`java'.  The comments in mlds.m said they should not get passed, the
code in ml_call_gen.m passed them as if they were output arguments, and
the code in ml_code_util declared them as if they were input arguments.

compiler/hlds_pred.m:
	Add some detailed comments about the meaning of the `arg_mode' type.

compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_code_gen.m:
	Ensure that arguments with arg_mode `unused' do not get passed,
	declared, or converted (respectively).

runtime/mercury_grade.h:
	Bump the binary compatibility version number for MLDS grades.
	This is needed because the calling convention for procedures
	with `unused' mode arguments has changed.
2003-02-14 09:58:41 +00:00
Peter Ross
f43612a3ee Avoid a bug where duplicate declarations were not being detected.
Estimated hours taken: 7
Branches: main

Avoid a bug where duplicate declarations were not being detected.
This prevented the compiler from bootstraping with MSVC in the grade
none.gc.tr.debug.

compiler/rtti.m:
	Remove the varset from the rtti_proc_label structure.  This is
	because rtti_proc_label is used as part of the key for the
	decl_set structure and sometimes the varset contains all the
	variables in the proc and sometimes only the headvariables
	leading to different keys representing the same declaration.
	Instead record the prog_var and its name together in an
	assoc_list.

compiler/code_util.m:
compiler/ml_code_util.m:
	Handle the new rtti_proc_label structure.
2002-11-01 09:56:54 +00:00
Fergus Henderson
bb783b892a Fix a problem where the library wasn't building in grade `hlc.agc'
Estimated hours taken: 1
Branches: main

Fix a problem where the library wasn't building in grade `hlc.agc'
anymore after petdr's change to make io_stream a foreign_type.

compiler/ml_code_util.m:
	Don't abort for foreign_types if accurate GC is enabled; instead,
	just don't generate any GC code for them.  In other words, assume
	that foreign_types are not allowed to point to the Mercury heap.

doc/reference_manual.texi:
	Document that C foreign_types must not point to the Mercury heap.
	But leave this documentation commented out for now, since
	`--gc accurate' is not yet fully implemented or officially supported.

library/io.m:
	Add code to mercury_fclose() to explicitly deallocate the
	MercuryFile structure pointed to by the io_stream C foreign_type,
	when not using conservative GC.
	This avoids a potential memory leak in those grades.
2002-05-15 08:17:08 +00:00
Peter Ross
ddd77f6f0e Get pragma foreign_type working for the C backend.
Estimated hours taken: 16
Branches: main

Get pragma foreign_type working for the C backend.

doc/reference_manual.texi:
    Document C pragma foreign_types.

compiler/prog_data.m:
    Add il_foreign_type and c_foreign_type which contain all the
    necessary data to output a foreign_type on the respective backends.
    Change foreign_language_type to refer to these new types.

compiler/prog_io_pragma.m:
    Handle the changes to foreign_language_type, and parse C
    foreign_type declarations.

compiler/hlds_data.m:
    Change the hlds_data__foreign_type type so that it records both the
    C and IL foreign types.  This will allow one to output both foreign
    type declarations when doing intermodule optimization.

compiler/make_hlds.m:
    Changes so that we store both the IL and C foreign types in
    hlds_data__foreign_type.
    Also add an error checking pass where we check that there is a
    foreign type for the back-end we are currently compiling to.

compiler/foreign.m:
    Change to_exported_type so that it works for both the C and IL
    backends by getting either the C or IL foreign_type definition.

compiler/llds.m:
compiler/pragma_c_gen.m:
    Change pragma_c_input and pragma_c_output so that they record
    whether or not a type is a foreign_type and if so what is the string
    which represents that foreign_type.

compiler/llds_out.m:
    When outputting pragma c_code variables that represent foreign_types
    get the casts correct.  Note that this adds the constraint on C
    foreign types that they are word sized, as all we are doing is
    casts, not boxing and unboxing.

compiler/mlds.m:
    Change mlds__foreign_type so that we store whether a type is an IL
    type or a C type.  It is the responsibility of the code generator
    that we never create a reference to a IL foreign type when on the C
    back-end, and vice versa.

compiler/mercury_to_mercury.m:
    Handle changes to prog_data__foreign_type.

compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
    Handle changes to hlds_data__foreign_type.

compiler/exprn_aux.m:
compiler/livemap.m:
compiler/middle_rec.m:
compiler/opt_util.m:
    Handle changes to the pragma_c_input and pragma_c_output types.

compiler/ml_code_util.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_c.m:
    Handle changes to mlds__foreign_type.
2002-05-07 11:03:17 +00:00
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
Fergus Henderson
6fe4a40db9 Fix a bug with accurate GC.
Estimated hours taken: 4
Branches: main

Fix a bug with accurate GC.

compiler/mlds.m:
	Rename the `is_tail_call' enumeration as `call_kind',
	rename the `call' alternative as `ordinary_call', and
	and add a new alternative `no_return_call'.

compiler/ml_call_gen.m:
	Use `no_return_call' rather than `tail_call' for calls to
	procecures with determinism `erroneous'.

compiler/ml_elim_nested.m:
	Fix a bug: when adding code to unchain the stack frame before
	tail calls, add a `return' statement after each tail call, to
	ensure that we don't try to unchain the stack frame twice.
	But don't do this for calls marked `no_return_call', since
	it's not needed in that case.  (This is mandatory, not just
	an optimization: we can't construct a proper return statement
	for no_return_calls, since the return values in a `no_return_call'
	might not match the return types of the caller.)

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/ml_util.m:
compiler/ml_tailcall.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
	Minor changes to handle the new `no_return_call' alternative
	and the renaming of `call' as `ordinary_call'.
2002-04-02 16:36:18 +00:00
Fergus Henderson
0acbaa7bca Some more steps towards accurate GC for the MLDS->C back-end.
Estimated hours taken: 24
Branches: main

Some more steps towards accurate GC for the MLDS->C back-end.

compiler/ml_closure_gen.m:
	Generate GC tracing code for some (XXX but still not yet all)
	of the local variables declared in closure wrapper functions.

compiler/ml_code_util.m:
	Add a new procedure ml_gen_maybe_gc_trace_code_with_typeinfo,
	for use by ml_closure_gen.m.

compiler/ml_elim_nested.m:
	Update the comments about accurate GC.

runtime/mercury.h:
	Include "mercury_layout_util.h", because the code that we
	generate for tracing variables in closure wrapper functions
	uses MR_materialize_closure_type_params().
2002-03-27 15:24:21 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

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

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

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

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

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

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

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

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

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

compiler/*.m:
	Change type_id to the more descriptive type_ctor everywhere.
2002-03-07 08:30:28 +00:00
Fergus Henderson
fc8b0fe968 Move the code for constructing closures from ml_unify_gen.m
Estimated hours taken: 1
Branches: main

Move the code for constructing closures from ml_unify_gen.m
into a new module ml_closure_gen.m.

compiler/ml_unify_gen.m:
compiler/ml_code_util.m:
	Move ml_make_boxed_types and fixup_builtin_module from
	ml_unify_gen.m to ml_code_util.m, for use by ml_closure_gen.m.

compiler/ml_unify_gen.m:
	Export ml_gen_new_object, for use by ml_closure_gen.m.

compiler/rtti_to_mlds.m:
	Import ml_closure_gen.m, for ml_gen_closure_wrapper.

compiler/ml_unify_gen.m:
compiler/ml_closure_gen.m:
	Move the code for constructing closures from ml_unify_gen.m
	into a new module ml_closure_gen.m.

compiler/notes/compiler_design.html:
	Mention the new module.
2002-03-04 07:31:38 +00:00
Fergus Henderson
63404237ff Generate closure layouts for the MLDS back-end.
Estimated hours taken: 24
Branches: main

Generate closure layouts for the MLDS back-end.

compiler/ml_unify_gen.m:
	Add code to generate closure layouts.
	XXX Note that we still don't fill in the MR_closure_id field yet.

compiler/stack_layout.m:
	Export stack_layout__represent_locn_as_int,
	for use by ml_unify_gen.m.

compiler/mercury_compile.m:
	Invoke the arg_info.m pass for the MLDS back-end, since the
	arg_infos are needed by the code in continuation_info.m which
	ml_unify_gen.m calls to generate closure layouts.

compiler/ml_elim_nested.m:
compiler/ml_util.m:
compiler/ml_code_util.m:
	Fix a bug, exposed by the changes above, which led to some
	dangling references.  The bug was that it was not hoisting out
	local static RTTI data even when this data was referred to by
	other static constants were being hoisted, because it was only
	checking for references via `var(mlds__var)' lvals, not via
	`data_addr_const(data_addr)' rvals.  The fix was to change the code
	for *_contains_var so that it accepts a data_name rather than
	a var_name, and counts references via data_addr_consts,
	and to change the code for ml_decl_is_static_const so that
	it just checks for `data(_)' rather than `data(var(_))'.
	Hoisting RTTI data also required adding code to ml_elim_nested.m
	to eliminate duplicate definitions.

compiler/rtti_to_mlds.m:
	Mark RTTI definitions as `final'; this is needed to ensure
	that they have the same flags (apart from the access) as
	ml_static_const_flags, so that ml_decl_is_static_const succeeeds
	for these.

compiler/ml_optimize.m:
	Update to reflect the interface changes in ml_util.m.

runtime/mercury_deep_copy_body.h:
	Delete a call to MR_fatal_error(), since it is no longer needed.

tests/hard_coded/Mmakefile:
	Re-enable the copy_pred and copy_pred_2 test cases for the
	MLDS back-end, since they now pass.
2002-03-03 13:45:47 +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
Michael Wybrow
0222feef78 Bug fixes and additions to the Java back-end so that it will now successfully
Estimated hours taken: 50
Branches: main


Bug fixes and additions to the Java back-end so that it will now successfully
compile and run mercury programs which contain higher order code as well as
non-deterministic code.
With some hacked up Mercury library code (in Java) I am able to compile 10 of
the 11 files in the tests/benchmarks directory into Java and run them to
receive the correct output.


mercury/compiler/mlds_to_java.m:
	Many small bug fixes.

	Disabled current (incomplete) name mangling code. All class, package
	and method names apart from java.* and mercury.runtime.* will be
	output as lowercase for the moment.

	Added code to prefix some classes/packages so we don't run into the
	problem of having a class or package name which is also a Java reserved
	word. This is the case with the mercury library modules int and char.

	Added code to implement commits.


mercury/compiler/java_util.m:
	Added a few missing Java reserved words.

mercury/compiler/ml_code_util.m:
	A small change so that in one case where they weren't, multiple return
	values are now generated in the MLDS.

mercury/java/Commit.java:
	Added this file, a throwable class used for the implementation of
	commits.

mercury/java/ProcAddr.java:
mercury/java/Compare.java:
mercury/java/Unify.java:
	Removed these files, they're now obsolete as they all use the standard
	interface for method pointers provided by MethodPtr.java.

mercury/java/TypeCtorInfo_Struct.java:
	Altered to reference mercury.runtime.MethodPtr instead of
	mercury.runtime.[Unify|Compare].
2002-02-08 00:42:22 +00:00
Fergus Henderson
ffea84686b Some more bug fixes for accurate GC with the MLDS->C back-end.
Estimated hours taken: 8
Branches: main

Some more bug fixes for accurate GC with the MLDS->C back-end.

With these changes, and a few hacks (see http://www.cs.mu.oz.au/research/
mercury/mailing-lists/mercury-reviews/mercury-reviews.0201/0188.html),
I was able to run all of the programs in tests/benchmarks in grade hlc.agc,
even with MERCURY_OPTIONS set to "-r10000" so as to run them enough times to
force garbage collection.

compiler/ml_elim_nested.m:
	- Fix a bug where we were not saving/restoring the stack chain
	  pointer when doing commits (setjmp/longjmp).
	- Fix a bug where we were not calling GC_check() for the nested
	  functions used for continuations in nondeterministic procedures.
	- Remove the GC tracing annotations from function arguments
	  once they have been put into the GC tracing function,
	  to avoid cluttering the generated C code.
	- Update the TODO list for accurate GC.

compiler/ml_code_util.m:
	Allocate type_infos used for GC tracing on the stack,
	rather than on the heap.  This avoids a problem where
	we were running out of heap space during garbage collection,
	because the tracing routines were themselves allocating heap space.

runtime/mercury_accurate_gc.c:
	Delete a call to MR_reset_redzone() in the MR_garbage_collect()
	function, since the MLDS accurate garbage collector doesn't use
	redzones.
	Also update a comment to reflect the change to ml_code_util.m.
2002-02-01 22:06:14 +00:00
Fergus Henderson
3e8cc77012 Various bug fixes for accurate GC with the MLDS->C back-end.
Estimated hours taken: 16
Branches: main

Various bug fixes for accurate GC with the MLDS->C back-end.

runtime/mercury.c:
	Fix a typo in the definition of the `stack_chain' global.

compiler/ml_code_util.m:
compiler/ml_call_gen.m:
	Fix several bugs:
	- generate appropriate GC tracing code for tracing type_infos
	  and typeclass_infos.  These need to be handled specially
	  because of the parameters of private_builtin:type_info/1 etc.
	  don't affect the representation of the type, and need to
	  be ignored (to avoid infinite recursion).
	- don't generate GC tracing code for no_type_info_builtin procedures,
	  because the generated GC tracing code would refer to
	  type_info arguments that don't get passed.
	- in ml_call_gen.m, we were generating incorrect GC tracing code
	  for the `conv_*' variables introduced to hold output arguments
	  of polymorphically typed procedures.

compiler/type_util.m:
library/private_builtin.m:
	Add types `sample_type_info' and `sample_typeclass_info',
	so that ml_code_util.m can use them when tracing type_infos
	and typeclass_infos (respectively).

library/private_builtin.m:
	Fix some software rot in gc_trace/1: add `MR_eng_' prefixes.

library/io.m:
runtime/mercury_library_types.h:
runtime/mercury_file.c:
	Implement stream ids for NATIVE_GC.
2002-01-30 12:47:12 +00:00
Fergus Henderson
71c25b3d11 More improvements to accurate GC for the MLDS->C back-end.
Estimated hours taken: 8
Branches: main

More improvements to accurate GC for the MLDS->C back-end.

runtime/mercury_accurate_gc.h:
runtime/mercury_accurate_gc.c:
	Add new routine MR_garbage_collect().

runtime/mercury_memory_handlers.c:
	Wrap `#ifndef MR_HIGHLEVEL_CODE' around some LLDS-specific
	code for accurate GC.

runtime/mercury_accurate_gc.c:
runtime/mercury_memory_handlers.c:
	Fix some software rot: missing `MR_' and `MR_eng_' prefixes.

runtime/mercury.h:
	Add MR_GC_check() macro, which invokes MR_garbage_collect()
	if needed.

compiler/mlds.m:
	Add gc_check as a new mlds__atomic_statement.

compiler/ml_elim_nested.m:
	Insert gc_check statements at the start of every procedure
	that does any heap allocation.

compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
	Minor changes to handle gc_check statements.

compiler/ml_code_util.m:
	Fix some bugs in the way that we were calling
	private_builtin__gc_trace/1.
2002-01-28 05:30:32 +00:00
Peter Ross
dffdb3fd0b Allow the foreign_type declaration to accept value types.
Estimated hours taken: 4
Branches: main

Allow the foreign_type declaration to accept value types.

compiler/prog_data.m:
    Add an indicator to il foreign types whether or not they are
    reference or value types.

compiler/prog_io_pragma.m:
    Parse whether or not the foreign type is a reference or a value type.

compiler/make_hlds.m:
    Decide whether or not a foreign_type is already boxed.

compiler/hlds_data.m:
compiler/mlds.m:
    Add to the foreign_type an indicator of whether or not it is already
    boxed.

compiler/mlds_to_il.m:
    Remove code which attempted to determine when a value type was
    incorrectly defined as a reference type.
    Unboxed types on the .NET backend are value types.
    Fix a bug where converting a value_class to a value_class was
    failing.

compiler/ilasm.m:
    Remove name_to_simple_type from the interface as it is no longer
    needed in mlds_to_il.

compiler/mercury_to_mercury.m:
    Output the new foreign_type format.

compiler/foreign.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
    Changes to handle the boxed indicator.


doc/reference_manual.texi:
    Document how to specify a value type.
2002-01-16 01:13:47 +00:00
Fergus Henderson
9aca3d48f4 Another substantial step towards supporting accurate garbage
Branches: main
Estimated hours taken: 50

Another substantial step towards supporting accurate garbage
collection for the MLDS->C back-end: generate code for the
GC tracing functions.

compiler/mlds.m:
	Add new fields to store, with each local variable or argument
	declaration, the code for the GC to trace that local variable
	or argument.

compiler/ml_code_util.m:
	Add a new procedure ml_gen_maybe_gc_trace_code to generate the
	code for GC tracing a variable.  The generated MLDS code calls
	private_builtin:gc_trace/1, passing the variable's address and
	the type_info for that variable.  This code is generated by
	invoking polymorphism__make_type_info_var to generate HLDS code
	to build the type_infos needed, and then calling ml_code_gen.m
	to convert that to MLDS.

library/private_builtin.m:
	Add a new procedure gc_trace, which calls MR_agc_deep_copy().
	This gets invoked by the code generated by ml_code_util.m.

compiler/polymorphism.m:
	Export polymorphism__make_type_info_var, for use by ml_code_util.m.

compiler/mercury_compile.m:
	Invoke the chain_gc_stack_frames pass before invoking the
	hoist_nested_functions pass, since otherwise it doesn't work.

compiler/handle_options.m
	Add a couple of checks for options that are not supported
	in combination with `--gc accurate'.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
	Various changes to handle the GC trace code field for variable and
	argument declarations.
2002-01-11 07:44:29 +00:00
Fergus Henderson
116cea5c24 Fix a bug in the --high-level-data version of the .NET back-end,
Branches: main
Estimated hours taken: 16

Fix a bug in the --high-level-data version of the .NET back-end,
where when constructing data types with polymorphically typed fields,
we were calling the constructor with incorrect (unboxed) argument types.

It was documented in mlds.m that handling this boxing/unboxing was the
responsibility of the MLDS->target code generator, but the MLDS didn't
contain enough information (in particular it was missing the unsubstituted
constructor argument types for new_object statements).  So I ended up
fixing it by doing this boxing in the HLDS->MLDS code generator.
This makes it more consistent with how we handle other cases where
boxing/unboxing is needed.

compiler/mlds.m:
	Update the documentation about who is responsible for handling
	boxing/unboxing for `new_object' statements (and improve the
	documentation about the same issue for `field' rvals).

compiler/ml_unify_gen.m:
	When generating new_object statements, look up the original
	(unsubstituted) types for the constructor arguments, and
	where necessary box the actual arguments to match.

compiler/mlds_to_il.m:
	Don't box arguments of new_object statements, since this
	is now done in ml_unify_gen.m.

compiler/type_util.m:
	Export type_util__get_cons_defn, for use by ml_unify_gen.m.
	Add some comments.

compiler/ml_code_util.m:
compiler/mlds_to_c.m:
	Improve the comments.

compiler/mlds_to_c.m:
	Avoid generating some unnecessary casts.
2001-11-08 11:48:02 +00:00
Fergus Henderson
b30433486a Avoid some unnecessary tag tests when using reserved address
Branches: main
Estimated hours taken: 4

Avoid some unnecessary tag tests when using reserved address
data representations.

compiler/hlds_data.m:
	Add new cons_tag alternative `single_functor'.
	This is equivalent to `unshared_tag(0)' except that it
	also means that there are no other primary tag values used.

	Previously this wasn't needed, since any tag tests
	against `unshared_tag(0)' would be marked as `cannot_fail'
	by determinism analysis.  However, now that we have
	reserved addresses, that is not sufficient: a tag test against
	`shared_with_reserved_address(null_pointer, unshared_tag(0))'
	is semidet, because it needs to first check for null,
	but if there are no other functors then it should NOT
	bother to check that the tag is zero.  We need the
	`single_functor' alternative to optimize that case.

compiler/make_tags.m:
	Assign `single_functor' representations rather than
	`unshared_tag(0)' if there are no other functors remaining.

compiler/ml_unify_gen.m:
compiler/unify_gen.m:
	Optimize away the tag test for `single_functor' alternatives.

compiler/bytecode_gen.m:
compiler/hlds_data.m:
compiler/type_ctor_info.m:
compiler/switch_util.m:
compiler/ml_unify_gen.m:
compiler/unify_gen.m:
	Minor changes to handle the new cons_tag alternative:
	treat it the same as `unshared_tag(0)'.

compiler/code_util.m:
compiler/unify_proc.m:
	Use `single_functor' rather than `unshared_tag(0)' for tuples.

compiler/ml_code_util.m:
	Add ml_gen_and and ml_gen_not, for use by compiler/ml_unify_gen.m.
2001-10-31 16:58:11 +00:00
Peter Ross
77a1261d3b Merge the foreign_type pragma changes from the dotnet branch to the main
Estimated hours taken: 10
Branches: main

Merge the foreign_type pragma changes from the dotnet branch to the main
branch, plus do some more development work to generalise the change.

compiler/prog_data.m:
    Add a type to hold the data from parsing a pragma foreign_type decl.

compiler/prog_io_pragma.m:
    Parse the pragma foreign_type.  This code is currently commented
    out, while we decide on the syntax.

compiler/hlds_data.m:
    Add a new alternative to hlds_type_body where the body of the type
    is a foreign type.

compiler/make_hlds.m:
    Place the foreign_type pragmas into the HLDS.

compiler/foreign.m:
    Implement to_type_string which replaces export__type_to_type_string,
    unlike export__type_to_type_string foreign__to_type_string takes an
    argument specifying which language the representation is meant to be
    in.  to_type_string also needs to take a module_info to handle
    foreign_types correctly.  To avoid the need for the module_info to
    be passed around the MLDS backend we provide a new type
    exported_type which provides enough information for an alternate
    version of to_type_string to be called.

compiler/export.m:
    Delete export__type_to_type_string.

compiler/llds.m:
    Since foreign__to_type_string needs a module_info, we add a new
    field to pragma_c_arg_decl which is the result of calling
    foreign__to_type_string.  This avoids threading the module_info
    around various llds passes.

compiler/mlds.m:
    Record with in the mercury_type the exported_type, this avoids
    passing the module_info around the MLDS backend.
    Also add the foreign_type alternative to mlds__type.
    Update mercury_type_to_mlds_type so that it handles types which are
    foreign types.

compiler/mlds_to_il.m:
    Convert a mlds__foreign_type into an ilds__type.

compiler/ilds.m:
    The CLR spec requires that System.Object and System.String be
    treated specially in the IL assembly so add them as simple types.

compiler/ilasm.m:
    Before outputting a class name into the IL assembly check whether it
    it can be simplified to a builtin type, and if so output that name
    instead as required by the ECMA spec.
    Changes for the addition of string and object as simple types.

doc/reference_manual.texi:
    Document the new pragma, this is currently commented out because it
    refers to syntax that has not yet been finalised.

compiler/fact_table.m:
compiler/llds_out.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/pragma_c_gen.m:
compiler/rtti_to_mlds.m:
    Changes to handle using foreign__to_type_string.

compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/recompilation_version.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
    Changes to handle the new hlds_type_body.

compiler/mercury_to_mercury.m:
    Output the pragma foreign_type declaration.

compiler/module_qual.m:
    Qualify the pragma foreign_type declarations.

compiler/modules.m:
    Pragma foreign_type is allowed in the interface.
2001-10-24 13:34:41 +00:00
Fergus Henderson
40e37d11cf Add compiler support for deciding when to use reserved addresses,
Estimated hours taken: 18
Branches: main

Add compiler support for deciding when to use reserved addresses,
and for generating code appropriately when they are used.

compiler/options.m:
doc/user_guide.texi:
	Add new options `--num-reserved-addresses'
	and `--num-reserved-objects'.

compiler/hlds_data.m:
	Add new type `reserved_address ---> null_pointer ; small_pointer(int) ;
	reserved_object(sym_name, arity)'.
	Add new cons_tag alternatives `reserved_address(reserved_address)'
	and `shared_with_reserved_address(list(reserved_address), cons_tag)'.
	Also add get_secondary_tag, for use by ml_type_gen.m.

compiler/ml_type_gen.m:
	Don't generate types for constructors represented using reserved
	addresses.  For constructors represented using reserved_object,
	generate the reserved object.
	Also, use get_secondary_tag, rather than just unifying with
	shared_remote/2, so that it works for
	shared_with_reserved_tag(_, shared_remote(_, _)).

compiler/make_tags.m:
	If --tags none and --num-reserved-addresses are both set,
	then assign null_pointer and small_pointer(int) representations
	to constants up to the value set in num-reserved-addresses.
	If --tags none and --high-level-code are both set,
	and more constants remain unassigned, then assign reserved_object
	representations for those constants, and generate static member
	variable declarations for the reserved_objects.

compiler/make_hlds.m:
	Pass down the type_id to assign_constructor_tags in make_tags.m,
	since it is needed for reserved_object representations.

compiler/ml_unify_gen.m:
compiler/unify_gen.m:
	Handle construction, deconstruction, and tag tests for
	types represented using reserved tags.
	(In unify_gen.m, only null_pointer and small_pointer(int)
	are supported; for reserved_object we call sorry/2).

compiler/ml_switch_gen.m:
compiler/switch_gen.m:
compiler/switch_util.m:
	Handle switches on types represented using reserved tags.
	XXX Currently we always use if-then-else chains for such
	    switches; this may not be efficient.

compiler/ml_code_util.m:
	Add ml_format_reserved_object_name.
	Also add accessibility parameter to ml_gen_static_const_defn,
	so that it can be used for generating the class member
	static constants used for reserved_objects.

compiler/ml_string_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
	Handle the new parameter to ml_gen_static_const_defn.

compiler/bytecode_gen.m:
	Call sorry/2 if types represented using reserved addresses are
	encountered.
2001-10-24 07:10:18 +00:00
Tyson Dowd
416ca83320 Merge changes to add attributes to the HLDS, MLDS and ILDS from the
Estimated hours taken: 2
Branches: main

Merge changes to add attributes to the HLDS, MLDS and ILDS from the
dotnet-foreign branch.  We don't merge the changes to add syntax for
attributes, as the syntax is still very experimental.

compiler/hlds_pred.m:
compiler/prog_data.m:
	Add attributes to the pred_info (they are a bit like markers,
	but are more than just boolean flags).

compiler/ilasm.m:
	Add custom attributes to appropriate positions (on assemblies,
	IL types and methods).

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_util.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
	Add mlds__attributes, which are the MLDS version of custom attributes.
	Convert hlds_pred__attributes into mlds__attributes.
	Add a list of mlds__attributes to the mlds__function defn.

compiler/mlds_to_il.m:
	Convert MLDS attributes to IL custom attributes.
2001-08-24 15:44:57 +00:00
Fergus Henderson
75895809ff Fix an XXX: give label functions "local" access.
Estimated hours taken: 0.5
Branches: main

compiler/ml_code_util.m:
	Fix an XXX: give label functions "local" access.

compiler/ml_unify_gen.m:
	Give wrapper functions access "private".
	Extra code is needed here to set this
	now that label functions have "local" access.
2001-07-13 08:04:41 +00:00
Tyson Dowd
bf0ed70782 Use a new mlds__function_body type to represent function bodies, as the old
Estimated hours taken: 0.75
Branches: main

Use a new mlds__function_body type to represent function bodies, as the old
usage of maybe/1 was error prone ("no" meant the function had been declared
using :- pragma external, not merely that the body was missing).

compiler/mlds.m:
	Add mlds__function_body type.

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
	Handle this change.
2001-07-12 15:44:58 +00:00
Peter Ross
4b0fdd8481 Back out the change to make ml_gen_label_func_decl_flags be
Estimated hours taken: 0.5
Branches: main

ml_code_util.m:
    Back out the change to make ml_gen_label_func_decl_flags be
    one_copy.

ml_unify_gen.m:
    Define a new function ml_gen_wrapper_func for generating wrapper
    functions. This function calls ml_gen_label_func but overrides the
    per_instance flag to be one_copy.
2001-07-11 10:20:11 +00:00
Peter Ross
a6d5d61cb5 Refactor the top level of mlds_to_il so that we only do one pass over
Estimated hours taken: 40
Branches: main

Refactor the top level of mlds_to_il so that we only do one pass over
the MLDS to generate the ILDS.  As a side effect of this change nondet
code now works again.

compiler/mlds_to_il.m:
    Do a MLDS to MLDS transformation which places all the procedures and
    data into the mercury_code class.  Then modify all the qualifiers to
    take account of this change to the code.
    Rewrite the top level so that it only does one pass over the MLDS
    data structure.
    Examine the flags when deciding which attributes to place on a
    method, field or class.

compiler/mlds.m:
    Add a new field to mlds__class_defn which is the list of
    defns which are constructors for this class.
    Add the functions mlds__append_mercury_code and mlds__append_name
    which append either "mercury_code" or an arbitary string to the
    module qualifier of a name.

compiler/ml_elim_nested.m:
    Rather then hardcoding the generation of the constructor for the
    environment class, we generate it here as an MLDS method.
    On the IL backend the mercury code is placed in a seperate class to
    the environment data, so the env_type decls must be public so as to
    be accessible from the code.

compiler/ml_code_util.m:
    Wrapper functions should be static methods not instance methods.
    Fix ml_gen_label_func_decl_flags to make this true.

compiler/rtti_to_mlds.m:
    Rtti data structures should be one_copy (ie static) not per_instance.

compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
    Misc changes to handle the additon of a list of constructors to the
    mlds__class_defn.

compiler/mlds_to_csharp.m:
compiler/mlds_to_mcpp.m:
    Use the function class_name rather then mercury_module_name_to_mlds.
2001-07-09 15:55:07 +00:00
Fergus Henderson
befb329aaf Add type information to the array_index operator.
Estimated hours taken: 8
Branches: main

Add type information to the array_index operator.
This is needed for both the GCC back-end and the IL back-end.

compiler/builtin_ops.m:
	In the array_index constructor for the unary_op type,
	add the array element type as a field.

compiler/ml_string_switch.m:
compiler/string_switch.m:
compiler/mlds_to_java.m:
	When generating array_index operators, generate the new field.

compiler/bytecode.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
	When consuming array_index operators, ignore the new field.

compiler/mlds_to_gcc.m:
	When consuming array_index operators, use the array element type,
	rather than wrongly assuming the element type is always 'MR_Integer'.

compiler/mlds_to_il.m:
	Add code to handle the array_index operator,
	rather than calling `throw_unimplemented'.

compiler/bytecode.m:
	Delete the reverse mode of binop_code.  This was not used,
	it was just there to get the compiler to check that we didn't
	map two different binary operators to the same code.  This
	mode no longer works, since we map array_index operators to
	the same code regardless of the the array element type.

compiler/rtti_to_mlds.m:
compiler/ml_string_switch.m:
compiler/ml_code_util.m:
	To avoid code duplication, move ml_string_type, which was defined in
	both rtti_to_mlds.m and ml_string_switch.m, into ml_code_util.m.

compiler/ml_string_switch.m:
	Minor changes to avoid some code duplication.

compiler/mlds_to_java.m:
	Fix a bug where it was using the wrong type for the `args' variable.
	Add an XXX comment about what looks to me like another bug.
2001-07-08 16:40:11 +00:00
Peter Ross
5c2103005e The .NET backend requires that names are not only qualified with their
Estimated hours taken: 4
Branches: main

The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from.  In this change we
back out a previous solution to this problem and implement a much
neater solution where we hide the package name in the abstract type
mlds_module_name.

This solution is neater because the package name shouldn't change once
the name is defined.  All that we may have to change is the qualifiers
to the name.

compiler/mlds.m:
    Add the package name to the abstract type mlds_module_name.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
    Back out previous solution.
2001-06-22 09:14:39 +00:00
Peter Ross
f092670758 The .NET backend requires that names are not only qualified with their
Estimated hours taken: 16
Branches: main

The .NET backend requires that names are not only qualified with their
namespace but the source package the name comes from.  In this change we
add to the name type the name of the source package which this name is
defined in.  This change will be needed for implementing foreign_class
in the .NET backend where it will no longer be possible to determine
the package name from the fully qualified name.

compiler/mlds.m:
    Add the new field to the mlds__fully_qualified_name type.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/rtti_to_mlds.m:
    Propogate the changes around.
2001-06-08 09:13:45 +00:00
Fergus Henderson
14ff8e7c3f Fix a bug in trd's previous change: it was not setting the "function
Estimated hours taken: 0.5
Branches: main

compiler/ml_code_util.m:
	Fix a bug in trd's previous change: it was not setting the "function
	without return value" field correctly for predicates.
2001-05-12 05:30:21 +00:00
Tyson Dowd
cbdd5a68d5 Minimize the amount of procedure name mangling done by the .NET backend.
Estimated hours taken: 5
Branches: main, dotnet-foreign

Minimize the amount of procedure name mangling done by the .NET backend.

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_util.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/rtti_to_mlds.m:
	Add the code_model and a boolean indicating whether this
	function (if it is a function) *doesn't* have a return value
	(i.e. it has a non-default mode).

	Also move is_output_det_function into ml_code_util.m and rename it
	ml_is_output_det_function.

compiler/mlds_to_il.m:
	Mangle much more carefully.  We still mangle in a predictable,
	context-insensitive manner, however we take advantage of the
	overloading available in the .NET backend to avoid name clashes
	in most cases.
2001-05-10 15:07:59 +00:00
Tyson Dowd
76ac44335d Implement a C# interface for the .NET backend.
Estimated hours taken: 45
Branches: main

Implement a C# interface for the .NET backend.

To use it, you currently need to set
	--backend-foreign-language csharp --use-foreign-language csharp
in your MCFLAGS.

The C# foreign language interface works by introducing a new sort of
MLDS statement called outline_foreign_proc.  outline_foreign_proc is expected
to be turned into a separate procedure in a separate file.  This is
quite different to normal foreign code which has been renamed as inline
target code, as it is really intended to be generated inline, inside the
generated code.

Because outline_foreign_proc is expected to be generated outside the
normal code, we don't need to generate variable renamings,
initializations, casts and other complicated interfacing code.

Any marshalling is done by the backend, which knows how to marshall
arguments across the boundary into the outline code and back.  In the
case of marshalling to C# from the .NET backend, we currently don't do
anything special (part of the point of .NET is that data
representation don't have to change very often just because you are
using different languages, so this is a property we should try to
preserve).

The actual implementation of the foreign code is therefore very simple.
Simply generate an appropriate procedure, and insert the user's code in
the middle.

The bulk of this change to delay the mangling of MLDS var names, so we
can still use the original user's var name when we output the outline
procedure (since the user's foreign code will refer to these var names,
it's important to keep them around).

compiler/foreign.m:
	Handle the csharp foreign language.

compiler/globals.m:
	Fix an XXX about converting to lowercase to do language name
	comparisons.
	Add new predicates to make conversion of foreign languages
	to strings more uniform.

compiler/handle_options.m:
	Don't set backend_foreign_language to the default if it has
	already been set by hand.

compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
	Delay the mangling of MLDS var names by keeping the variable
	number around until the output phase.

	Slightly generalize the handling of foreign language interfacing.
	Handle C# foreign language interfacing.

	Add value_output_vars to the ml_gen_info, which are the variables
	returned rather than passed by reference.  We need to know
	these variables for C# interfacing so that we can handle the return
	value of the forwarding function.

	Mark the beginning and end of the MLDS foreign language processing as
	a "sub-module" (in comments at least).  Later I may put this code
	into a separate module.

	Rename some predicates from c_code to foreign_code.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds.m:
	Add outline_foreign_proc which is handled differently to the old
	target_code (which has been renamed inline_target_code).

	Change the definiton for mlds__var_name.

compiler/mlds_to_c.m:
	Factor out mlds_output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_csharp.m:
	A new module to generate C# code suitable for foreign language
	interfacing.  This is largely lifted from the MC++ code, with a few
	changes to the output syntax.

compiler/mlds_to_il.m:
	Return the set of foreign languages processed instead of a bool
	saying wither MC++ was present.  This is so we can generate the
	appropriate output .cs or .cpp files, and because we need to keep
	track of all the external assembly references we need to put in the
	.il file.

	Handle the inline_target_code and mlds__var_name changes.

compiler/mlds_to_ilasm.m:
	Output .cpp and .cs files conditionally.
	Factor out output_to_file.
	Move MC++ output code to mlds_to_mcpp.m

compiler/mlds_to_java.m:
	Factor out output_to_file.
	Handle the new var_name type, and the new target_code constructors.

compiler/mlds_to_mcpp.m:
	New file to handle generating MC++ code suitable for foreign language
	interfacing.

compiler/options.m:
	Add a way of setting the backend-foreign-language option.

compiler/passes_aux.m:
	Add output_to_file which is used by the MLDS backend to generate
	output files.

compiler/prog_data.m:
	Uncomment csharp as a foreign language.
2001-05-02 11:36:41 +00:00
Julien Fischer
00d8243570 General improvements and bug fixes to the MLDS backend, most
Estimated hours taken: 20

General improvements and bug fixes to the MLDS backend, most
of which were prompted by working on the Java backend.

The definition of mlds__lval now includes type information for
variables.  This is necessary because if enumerations are treated
as objects (as in the Java backend) rather than integers we need to know
when to create new objects.  At the level this occurs there was
previously no way to distinguish between an integer that is an integer,
and one that represents an enumeration.

Added the access specifier `local' to the declaration flags.  This fixes
a bug in which the local variables of a function were being declared
`private'.

Redefined ctor_name so that they are fully qualified.  This was necessary
because the Java backend represents discriminated unions as nested
classes and we need to be able to determine the fully qualified name of
the constructor in order to call it, do casts, etc.

Added `mlds__unknown_type' to `mlds__type'.  This is due to the change
in the definition of mlds_lval above.  In ml_code_util.m, env_ptr's are
created as dangling references.  The new definition of mlds__lval expects
there to be a type as well, but at this point it hasn't been
generated (and won't be until the ml_elim_nested pass).  Rather than just
guess the type we should declare the type to be unknown and print out an
error message if an unknown type makes it through to one of the backends.

Fixed a bug in the `--det-copy-out' option.

Shifted code for detecting entry point to main/2 from mercury_compile.m
to ml_util.m

compiler/mercury_compile.m:
compiler/ml_util.m:
	Shifted code for detecting entry point to main/2 from mercury_compile.m
	to ml_util.m
compiler/mlds.m:
	Added `local' as an access specifier.
	Extended definition of mlds__lval to include type information
	for variables.
	Added `mlds__unknown_type' to the mlds types so that when
	the compiler generates variables without yet knowing their
	type we can mark them as this, rather than hoping that the
	correct types eventually get added.
	Redefined ctor_name so that it is fully qualified.
	Made changes to comments to reflect above changes.

compiler/ml_code_gen.m:
	Mark the generated functions as `one_copy' rather than `per_instance',
	so that they get generated as static methods for the Java back-end.
	Fixed a bug with the --det-copy-out option.

compiler/ml_code_util.m:
	Fixed a bug that was causing the wrong declaration flags to be
	set for fields in du constructors.
	Changed the name of the predicate `ml_qualify_var' to
	`ml_gen_var_lval'.

compiler/ml_type_gen.m:
	Mark the generated types as `one_copy' rather than `per_instance',
	so that they get generated as static nested classes for the Java
	back-end.
	Changed comments to reflect that classes and enumeration constants
	should be static.
	Export functions that generate declaration flags because they
	are used in other modules as well.
	Added a new predicate `ml_gen_mlds_field_decl' that correctly
	generates fields of classes in discriminated unions.

compiler/ml_unify_gen.m:
	Changed the code that generates ctor_id's so that it generates
	the new sort.

compiler/ml_call_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_tailcall.m:
compiler/mlds_to_il.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_ilasm.m:
compiler/rtti_to_mlds.m:
	Fixed things so that they conform to the changes above.
2001-02-20 07:52:19 +00:00
Fergus Henderson
4e44dfb287 Fix a bug with the handling of commits in the high-level C back-end.
Estimated hours taken: 12

Fix a bug with the handling of commits in the high-level C back-end.

It was implementing commits via calls to setjmp()/longjmp(),
but ANSI/ISO C says that longjmp() is allowed to clobber the values
of any non-volatile local variables in the function that called setjmp()
which have been modified between the setjmp() and the longjmp().

The fix is that whenever we generate a commit, we put it in its own
nested function, with the local variables (e.g. `succeeded',
plus any outputs from the goal that we're committing over)
remaining in the containing function.  This ensures that
none of the variables which get modified between the setjmp()
and the longjmp() and which get referenced after the longjmp()
are local variables in the function containing the setjmp().

[The obvious alternative of declaring the local variables in the
function containing setjmp() as `volatile' doesn't work, since
the assignments to those output variables may be deep in some
function called indirectly from the goal that we're committing
across, and assigning to a volatile-qualified variable via a
non-volatile pointer is undefined behaviour.  The only way to
make it work would be to be to declare *every* output argument
that we pass by reference as `volatile T *'.  But that would
impose distributed fat and would make interoperability difficult.]

compiler/options.m:
	Add a new option `--put-commits-in-own-function'.

compiler/handle_options.m:
	If the target is high-level C, set the
	`--put-commits-in-own-function' option.

compiler/ml_code_util.m:
	Add a routine for accessing the new option.

compiler/ml_code_gen.m:
	If the new option is set, generate each commit in its own
	nested function.

tests/hard_coded/Mmakefile:
tests/hard_coded/setjmp_test.m:
tests/hard_coded/setjmp_test.exp:
	A regression test.
	Previous versions of the compiler generated code for this test
	case that did the wrong thing on *some* systems.
2000-12-10 07:39:47 +00:00
Fergus Henderson
4be69fa961 Eliminated a lot of the dependencies on the the `code_model' type,
Estimated hours taken: 6

Eliminated a lot of the dependencies on the the `code_model' type,
and move that type from llds.m into a new module `code_model'.
The aim of this change is to improve the modularity of the compiler by
reducing the number of places in the compiler front-end that depend
on back-end concepts and the number of places in the MLDS back-end
which depend on the LLDS.

compiler/code_model.m:
	New module.  Contains the code_model type and associated
	procedures.

compiler/llds.m:
	Move the code_model type into code_model.m.

compiler/hlds_goal.m:
	Move the goal_info_get_code_model procedure into code_model.m,
	to avoid having the HLDS modules import code_model.

compiler/hlds_out.m:
	Delete `hlds_out__write_code_model', since it wasn't being used.

compiler/hlds_pred.m:
	Move the proc_info_interface_code_model procedure into code_model.m,
	to avoid having the HLDS modules import code_model.

compiler/goal_path.m:
	When computing the `maybe_cut' field for `some' goals,
	compute it by comparing the determinism rather than by
	comparing the goal_infos.

compiler/unique_modes.m:
	Use determinism and test for soln_count = at_most_many
	rather than using code_model and testing for model_non.

compiler/inlining.m:
	Test for determinism nondet/multi rather than testing
	for code_model model_non.

compiler/hlds_pred.m:
compiler/det_report.m:
	Change valid_code_model_for_eval_method, which succeeded unless
	the eval_method was minimal_model and the code_model was model_det,
	to valid_determinism_for_eval_method, which succeeds unless the
	eval_method is minimal_model and the determinism cannot fail.
	As well as avoiding a dependency on code_model in the HLDS
	modules, this also fixes a bug where det_report could give
	misleading error messages, saying that `multi' was a valid
	determinism for `minimal_model' predicates, when in fact the
	compiler will always report a determinism error if you declare
	a `minimal_model' predicate with determinism `multi'.
	(Actually the code in which this bug occurs is in fact
	unreachable, but this is no doubt also a bug... I'll address
	that one in a separate change.)

compiler/lookup_switch.m:
	Simplify the code a bit by using globals__lookup_*_option
	rather than globals__get_option and then getopt__lookup_option.

compiler/*.m:
	Add `import_module' declarations for `code_model', and in some
	cases remove `import_module' declarations for `llds'.
2000-11-23 04:32:51 +00:00
Fergus Henderson
e10abb4c71 Add some more comments, to clarify things that Tyson
Estimated hours taken: 0.25

compiler/ml_code_util.m:
compiler/mlds.m:
	Add some more comments, to clarify things that Tyson
	identified in his review of my last change.
2000-11-14 07:40:51 +00:00
Fergus Henderson
612865de05 Get the MLDS back-end to generate better code for string switches.
Estimated hours taken: 8

Get the MLDS back-end to generate better code for string switches.

compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
	Move the routines for generating static constants from
	ml_unify_gen.m to ml_code_util.m, for use by ml_string_switch.m.

compiler/ml_string_switch.m:
	New file, adapted from string_switch.m.
	This handles generation of string switches for the MLDS back-end.
	It generates string switches using string hashing and either
	computed gotos or int switches.

compiler/ml_switch_gen.m:
	Add support for string switches.
	Export the target_supports_* predicates, for use in ml_string_switch.m.
	(Perhaps these predicates should be moved into a different module?)
	Add `target_supports_goto'.

compiler/notes/compiler_design.html:
	Mention the new module.  Also mention other MLDS modules that
	have been recently added and not yet documented here.
2000-11-09 04:08:31 +00:00
Fergus Henderson
dd43cdab61 Get the MLDS back-end to generate better code for switches.
Estimated hours taken: 8

Get the MLDS back-end to generate better code for switches.
It now compiles Mercury switches on int/char/enums into C switches.

compiler/mlds.m:
	Add `switch' as a new alternative in the `mlds__stmt' type.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
	Minor changes to handle the new `switch' statement.

compiler/ml_code_gen.m:
	Move the code for handling switches to ml_switch_gen.m.
	Export `ml_gen_goal', for use in ml_switch_gen.m.

compiler/ml_switch_gen.m:
compiler/ml_dense_switch.m:
	New files, adapted from switch_gen.m and dense_switch.m, but
	with significant changes.  These now handle three forms of switch:
	    - dense switches, implemented as computed gotos;
	    - "direct mapped" switches, which get implemented using the
	      MLDS switch statement, which in turn gets mapped to the
	      target language's switch statement;
	    - if-then-else chains

compiler/ml_code_util.m:
	Add a label counter to the ml_gen_info, and define predicates
	for allocating new labels.

compiler/mlds_to_c.m:
	Output switch statements.  Also fix a layout bug in the output:
	make sure we output newlines at the end of comments.

compiler/mlds_to_il.m:
	Call error/1 for MLDS switch statements.  The code generator
	will generate MLDS computed_gotos (which map to IL `switch'
	instructions) rather than MLDS switch statements, so we should
	never get MLDS switch statements here.

compiler/options.m:
	Add a new option `--prefer-switch', defaulting to enabled,
	which says to generate switches rather than computed gotos
	where possible.
2000-11-08 07:23:11 +00:00
Fergus Henderson
4fd150c78f Change the MLDS calling convention so that for model_det Mercury functions
Estimated hours taken: 6

Change the MLDS calling convention so that for model_det Mercury functions
with output mode results, the function results get mapped to MLDS function
return values rather than to by-ref parameters.  The rationale for this is
to make interoperability simpler (especially for the IL & Java back-ends).

compiler/lambda.m:
	Change the rules for compatibility of closures so that for
	MLDS grades function closures are not treated as compatible
	with predicate closures.

compiler/ml_code_util.m:
	Change ml_gen_params so that it takes a pred_or_func parameter, and
	for model_det functions it maps the output-moded function results
	to MLDS return values.

compiler/ml_code_gen.m:
	For model_det functions with output mode results,
	return the function result by value.
	Rename the `output_vars' field of the ml_gen_info as
	`byref_output_vars'.

compiler/ml_call_gen.m:
	Pass down the pred_or_func parameter to ml_gen_params.
	For calls to model_det functions with output mode results,
	return the function result by value.

compiler/hlds_goal.m:
	Add new predicate generic_call_pred_or_func, for use by ml_call_gen.m.

compiler/ml_unify_gen.m:
	Modify the code for generating wrapper functions for closures so
	that it reflects the new calling convention for Mercury functions.

compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/ml_code_gen.m:
	Don't handle model_det functions with output mode results specially
	in `pragma export' anymore, since the internal MLDS form now
	has the same prototype as the exported one.
2000-10-30 07:09:04 +00:00