Commit Graph

177 Commits

Author SHA1 Message Date
Zoltan Somogyi
d5d5986472 Implement lookup switches in which a switch arm may contain more than one
Estimated hours taken: 40
Branches: main

Implement lookup switches in which a switch arm may contain more than one
solution, such as this code here:

	p(d, "four", f1, 4.4).
	p(e, "five", f2, 5.5).
	p(e, "five2", f3(5), 55.5).
	p(f, "six", f4("hex"), 6.6).
	p(g, "seven", f5(77.7), 7.7).
	p(g, "seven2", f1, 777.7).
	p(g, "seven3", f2, 7777.7).

Such code occurs frequently in benchmark programs used to evaluate the
performance of tabled logic programming systems.

Change frameopt.m, which previously worked only on det and semidet code,
to also work for nondet code. For predicates such as the one above, frameopt
can now arrange for the predicate's nondet stack frame to be created only
when a switch arm that has more than one solution is selected.

compiler/lookup_switch.m:
	Extend the existing code for recognizing and implementing lookup
	switches to recognize and implement them even if they are model_non.

compiler/lookup_util.m:
	New module containing utility predicates useful for implementing
	both lookup switches, and in the future, lookup disjunctions (i.e.
	disjunctions that correspond to a nondet arm of a lookup switch).

compiler/ll_backend.m:
	Include the new module.

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

compiler/global_data.m:
	Move the job of filling in dummy slots to our caller, in this case
	lookup_switch.m.

compiler/frameopt.m:
	Generalize the existing code for delaying stack frame creation,
	which worked only on predicates that live on the det stack, to work
	also on predicates that live on the nondet stack. Without this,
	predicates whose bodies are model_non lookup switches would create
	a nonstack stack frame before the switch is ever entered, which
	is wasteful if the selected switch arm has at most one solution.

	Since the structure of model_non predicates is more complex (you can
	cause a branch to a label by storing its address in a redoip slot,
	you can succeed from the frame without removing the frame), this
	required considerable extra work. To make the new code debuggable,
	record, for each basic block that needs a stack frame, *why* it
	needs that stack frame.

compiler/opt_util.m:
	Be more conservative about what refers to the stack. Export some
	previously internal functionality for frameopt. Turn some predicates
	into functions, and rename them to better reflect their purpose.

compiler/opt_debug.m:
	Print much more information about pragma_c and call LLDS instructions.

compiler/prog_data.m:
	Add an extra attribute to foreign_procs that says that the code
	of the foreign_proc assumes the existence of a stack frame.
	This is needed to avoid frameopt optimizing the stack frame away.

compiler/add_pragma.m:
	When processing fact tables, we create foreign_procs that assume
	the existence of the stack frame, so set the new attribute.

compiler/pragma_c_gen.m:
	When processing foreign_procs, transmit the information in the
	attribute to the generated LLDS code.

compiler/llds.m:
	Rename the function symbols referring to the fixed slots in nondet
	stack frames to make them clearer and to avoid overloading function
	symbols such as curfr and succip.

	Rename the function symbols of the call_model type to avoid overloading
	the function symbols of the code_model type.

	Add a new field to the c_procedure type giving the code_model of the
	procedure, and give names to all the fields.

	Describe the stack slots used by lookup switches to the debugger
	and native gc.

compiler/options.m:
doc/user_guide.texi:
	Add a new option, --debug-opt-pred-name, that does when the existing
	--debug-opt-pred-id options does, but taking a user-friendly predicate
	name rather than a pred_id as its argument.

compiler/handle_options.m:
	Process --debug-opt-pred-name, and make --frameopt-comments imply
	--auto-comments, since it is not useful without it.

	Reformat some existing comments that were written in the days of
	8-space indentation.

compiler/optimize.m:
	Implement the new option.

	Use the new field of the c_procedure type to try only the version
	of frameopt appropriate for the code model of the current procedure.

	Do a peephole pass after frameopt, since frameopt can generate code
	sequences that peephole can optimize.

	Make the mechanism for recording the process of optimizing procedure
	bodies more easily usable by including the name of the optimization
	that created a given version of the code in the name of the file
	that contains that version of the code, and ensuring that all numbers
	are two characters long, so that "vi procname*.opt*" looks at the
	relevant files in the proper chronological sequence, instead of having
	version 11 appear before version 2.

compiler/peephole.m:
	Add a new optimization pattern: a "mkframe, goto fail" pair (which
	can be generated by frameopt) should be replaced by a simple "goto
	redo".

compiler/code_gen.m:
	Factor out some common code.

compiler/llds_out.m:
	Ensure that C comments nested inside comment(_) LLDS instructions
	aren't emitted as nested C comments, since C compilers cannot handle
	these.

compiler/code_info.m:
compiler/code_util.m:
compiler/continuation_info.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
compiler/middle_rec.m:
compiler/ml_code_gen.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/stack_layout.m:
compiler/transform_llds.m:
compiler/var_locn.m:
	Conform to the change to prog_data.m, opt_util.m and/or llds.m.

compiler/handle_options.m:
	Don't execute the code in stdlabel.m if doing so would cause a compiler
	abort.

tests/hard_coded/dense_lookup_switch_non.{m,exp}:
	New test case to exercise the new algorithm.

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

tests/hard_coded/cycles.m:
	Make this test case conform to our coding convention.
2006-04-26 03:06:29 +00:00
Julien Fischer
459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00
Zoltan Somogyi
12deb40264 Rename all the get access predicates in these modules that don't
Estimated hours taken: 0.1
Branches: main

compiler/hlds_clauses.m:
compiler/hlds_pred.m:
	Rename all the get access predicates in these modules that don't
	already have put "get" in their name. (The names of the set access
	predicates were OK already.)

compiler/*.m:
	Conform to the above.

All this was done by this sed script:

s/clauses_info_varset/clauses_info_get_varset/
s/clauses_info_explicit_vartypes/clauses_info_get_explicit_vartypes/
s/clauses_info_vartypes/clauses_info_get_vartypes/
s/clauses_info_headvars/clauses_info_get_headvars/
s/clauses_info_clauses_rep/clauses_info_get_clauses_rep/
s/clauses_info_rtti_varmaps/clauses_info_get_rtti_varmaps/
s/pred_info_import_status/pred_info_get_import_status/
s/pred_info_arg_types/pred_info_get_arg_types/
s/pred_info_typevarset/pred_info_get_typevarset/
s/pred_info_tvar_kinds/pred_info_get_tvar_kinds/
s/pred_info_procedures/pred_info_get_procedures/
s/proc_info_context/proc_info_get_context/
s/proc_info_varset/proc_info_get_varset/
s/proc_info_vartypes/proc_info_get_vartypes/
s/proc_info_headvars/proc_info_get_headvars/
s/proc_info_inst_varset/proc_info_get_inst_varset/
s/proc_info_maybe_declared_argmodes/proc_info_get_maybe_declared_argmodes/
s/proc_info_argmodes/proc_info_get_argmodes/
s/proc_info_maybe_arglives/proc_info_get_maybe_arglives/
s/proc_info_declared_determinism/proc_info_get_declared_determinism/
s/proc_info_inferred_determinism/proc_info_get_inferred_determinism/
s/proc_info_goal/proc_info_get_goal/
s/proc_info_can_process/proc_info_get_can_process/
s/proc_info_rtti_varmaps/proc_info_get_rtti_varmaps/
s/proc_info_eval_method/proc_info_get_eval_method/
s/proc_info_is_address_taken/proc_info_get_is_address_taken/
s/proc_info_stack_slots/proc_info_get_stack_slots/
s/proc_info_liveness_info/proc_info_get_liveness_info/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
2006-03-27 09:36:34 +00:00
Julien Fischer
a4519ed079 Move the all-solutions predicates from the library module std_util into their
Estimated hours taken: 4
Branches: main

Move the all-solutions predicates from the library module std_util into their
own module, solutions.

Move semidet_fail, semidet_succeed, cc_multi_equal and dynamic cast from
std_util.m into builtin.m.

Add some more utility functions for performing determinism or purity casts.
(The later are primarily intended for use by solver implementors.)

library/std_util.m:
	Move the all-solutions predicates into their own module, solutions.m.
	For now there are (obsolete) forwarding predicates from this module to
	the new one.  The forwarding predicates will be included in the
	upcoming 0.13 release and then removed in later versions.

	Move semidet_succeed, semidet_fail, cc_multi_equal and dynamic_cast
	to builtin.m

library/solutions.m:
	New file.  This is the new home for the all-solutions predicates.
	This is pretty much cut and pasted from std_util (with module
	qualifiers updated accordingly).  I've rearranged the code in a more
	top-down fashion as per our current coding standard.

library/builtin.m:
	Move semidet_fail/0, semidet_succeed/0, cc_multi_equal/2 and
	dynamic_cast/2 to this module.

	Add semidet_true/0 and semidet_false/0 as synonyms for semidet_fail/0
	and semidet_succeed/0.

	Add impure_true/0 and semipure_true/0.  These are useful for performing
	purity casts, e.g. in solver implementations.

library/library.m:
	Add the new module.

NEWS:
	Announce the changes.

library/*.m:
	Update to conform to the above.

compiler/const_prop.m:
	Update evaluate_semidet_call/5 with the new module name for
	dynamic_cast.

compiler/*.m:
	Module qualify calls to solutions to either disambiguate them from the
	versions in std_util (where they weren't module qualified) or change
	the module qualifier where they were (to avoid warnings about calls to
	the now deprecated versions).

tests/debugger/declarative/solutions.*:
	Rename this module as the name conflicts with the new library module.

tests/debugger/declarative/solns.*:
	Renamed version of above (with updated expected output).

tests/debugger/declarative/Mmakefile:
	Handle the renamed version of the solutions test.

tests/debugger/all_solutions.m:
tests/debugger/declarative/args.m:
tests/debugger/declarative/library_forwarding.m:
tests/hard_coded/constant_prop_2.m:
tests/invalid/multisoln_func.m:
tests/invalid/one_member.m:
tests/invalid/promise_equivalent_claueses.m:
tests/valid/simplify_bug2.m:
tests/valid/solv.m:
	Update to conform to the above changes.

sample/solutions/*.m:
	Update to conform to the above changes.
2006-03-24 04:40:59 +00:00
Zoltan Somogyi
3ebda6545f Move the stuff currently in hlds_pred.m that deals with clauses into a new
Estimated hours taken: 1.5
Branches: main

Move the stuff currently in hlds_pred.m that deals with clauses into a new
module, hlds_clauses.m.

Move the stuff currently in hlds_pred.m that deals with RTTI into a new
module, hlds_rtti.m.

Move the stuff currently in hlds_module.m that deals with predicate tables
into a new module, pred_table.m.

These changes make hlds_pred.m and hlds_module.m much more cohesive, but there
are no changes in algorithms.

compiler/hlds_clauses.m:
compiler/hlds_rtti.m:
compiler/pred_table.m:
	New modules as described above. In some cases, fix mixleading or
	ambiguous predicate names in the process, and convert a few predicates
	to functions.

compiler/hlds_pred.m:
compiler/hlds_module.m:
	Delete the stuff moved to other modules.

compiler/*.m:
	In modules that need the functionality moved a new module, import
	the new module. It is rare for all the new modules to be needed,
	and many modules don't need any of the new modules at all. (For
	example, of the 200+ modules that import hlds_module.m, only about 40
	need pred_table.m.)

	Conform to the few minor changes to e.g. predicate names.

compiler/notes/compiler_design.html:
	Document the new modules.
2006-03-24 03:04:20 +00:00
Zoltan Somogyi
be5b71861b Convert almost all the compiler modules to use . instead of __ as
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Convert almost all the compiler modules to use . instead of __ as
	the module qualifier.

	In some cases, change the names of predicates and types to make them
	meaningful without the module qualifier. In particular, most of the
	types that used to be referred to with an "mlds__" prefix have been
	changed to have a "mlds_" prefix instead of changing the prefix to
	"mlds.".

	There are no algorithmic changes.
2006-03-17 01:40:46 +00:00
Zoltan Somogyi
5b8f96f61d Prepare for an extension of promise_equivalent_solutions that will allow us
Estimated hours taken: 5
Branches: main

Prepare for an extension of promise_equivalent_solutions that will allow us
to better handle values of user-defined types. The problem is that currently,
the deconstruction of a value of such a type can be followed only by code that
cannot fail, otherwise the cc_multi deconstruction is not in the required
single-solution context. If the following code is naturally semidet, this
can be worked around by turning it into det code returning a maybe and testing
the maybe outside the promise_equivalent_solutions, but this is inefficient,
and in any case it does not generalize to nondet code without even more
horrendous inefficiency and inconvenience. (You have to create a nondet closure
and call it outside the promise_equivalent_solutions.)

The solution I came up with is something is to have a construct that contains

	- a list of deconstructions on types with user-defined equality,
	- a goal, and
	- the list of outputs of that goal.

The idea is that this would be transformed into a conjunction of the first and
second items, and wrapped inside a special kind of conj that provides a scope
for the implicit promise, which is that the set of solutions of the goal in
the second item doesn't depend on what concrete terms the deconstructions
in the first item return out of the set of concrete terms they *could* return.
The deconstructions in the first item would be marked to tell determinism
analysis to effectively ignore the fact that they involve user-defined
equality.

The actual addition of that construct is left for a future change, after we
agree on the syntax.

compiler/hlds_goal.m:
	Generalize the existing promise_equivalent_solutions scope to a
	promise_solutions scope with a flag that says whether in the source
	code it was originally the existing "promise_equivalent_solutions"
	construct or the new construct (which doesn't exist yet, but is
	indicated by the symbol "same_solutions" for now).

	Replace the conj and par_conj hlds_goal_exprs with a single goal
	expression: conj with an additional argument which is either plain_conj
	or parallel_conj. This was part of an earlier design in which a third
	kind of disjunction took the role now assigned to the new kind of
	promise_solutions scope, but turned out to be a good idea anyway,
	since in many places the compiler does treat the two kinds of
	conjunctions the same. This part of the change is responsible for the
	fact that this change results in a net *reduction* of about 40 lines.

	Move the most frequently used kinds of goal expressions to the front
	of the type declaration to allow the compiler to make better decisions
	about tag allocation.

	Add the goal marker we will add to the deconstructions in the first
	item.

	Replace the true_goal and fail_goal predicates with functions to make
	them easier to use, and rename their variants that take a context
	argument to avoid unnecessary ambiguity.

compiler/*.m:
	Conform to the change in hlds_goal.m.

	Misc changes to make code more robust, e.g. replacing semidet
	predicates on goal expressions with functions returning bool.

	Misc cleanups, e.g. removal of unnecessary module qualifications
	that made lines too long, renaming predicates whose names include
	"disj" if they are also used to process parallel conjunctions (since in
	both parallel conjunctions and in disjunctions the goals are
	independent), and turning semidet predicates that switch on goal
	expressions into bool functions (to make similar changes more rebust
	in the future).
2006-02-24 05:49:43 +00:00
Zoltan Somogyi
4d377aba26 Fix a bug reported by Greg Duck. The bug was that the compiler always generated
Estimated hours taken: 5
Branches: main

Fix a bug reported by Greg Duck. The bug was that the compiler always generated
a global variable of type MR_Word for each mutable, but could then assign
variables of other types to and from this global. If this other type is
float, the assignments discard the fractional part. If this other type
is something else, the result can be even worse.

There are two ways to fix this discrepancy. One is to change the type of the
global, and the other is to change the type of the variables it is assigned
to and from. The former looks cleaner, but it would mean that every call
to the get predicate would require a boxing operation, and that can be
relatively slow, since (e.g. for floats) it may require allocating a heap cell.
This diff implements both solutions.

We use the second solution on the LLDS backend because of its better
performance. We have to use the first solution on the MLDS backend,
because on that backend the type of the mutable variable is reflected
in the signature of the getter and setter predicates (whereas on the
LLDS backend all arguments are always MR_Words).

compiler/options.m:
	Add an internal-only option that controls whether we use the first
	solution or the second.

compiler/handle_options.m:
	Make the MLDS backend imply the first solution.

compiler/prog_data.m:
	For each argument of a foreign_proc item, record whether we want to
	keep it boxed in the foreign code.

	Add a foreign_proc attribute that asks for every arg to be kept boxed.
	We can attach this to the mutable implementation foreign_procs we write
	out to .opt files. This attribute is deliberately undocumented since
	users should never use it.

compiler/make_hlds_passes.m:
	For each argument of the get and set foreign_procs we create for
	mutables, record that we do want to keep it boxed.

	Move the action of creating the foreign code for the mutable's
	declaration and definition to the third pass, since during the second
	pass we don't necessarily know yet what its foreign type is (we may not
	have processed a foreign_type declaration affecting it). Move the code
	for creating the foreign code here from prog_mutable, since it depends
	on the HLDS (and prog_mutable.m is in the parse_tree package).

	Hoist some error handling code to put it where it belongs,
	and to avoid some errors being reported twice.

compiler/hlds_goal.m:
	For each argument of a foreign_proc goal, record whether we want to
	keep it boxed in the foreign code.

compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
compiler/ml_call_gen.m:
	If a foreign_proc argument is noted as being kept boxed in the
	foreign_proc code, then keep it that way.

compiler/prog_io_pragma.m:
	Parse the new foreign_proc annotation.

compiler/simplify.m:
	If a foreign_proc has the always_boxed annotation, attach this info
	to each of its args. We do this here because simplify is guaranteed
	to be executed before all the code that may inspect these arguments.
	Since nothing ever deletes an always_boxed annotation of a foreign_proc
	arg, the code that attaches the annotation is idempotent, so the fact
	that the compiler executes simplify twice is not a problem.

compiler/*.m:
	Minor changes to conform to the changes in data structures above.

compiler/prog_type.m:
	Move a function definition from prog_mutable to prog_type, and
	fix the lack of abstraction in its code.

compiler/prog_mutable.m:
	Delete the code moved to make_hlds_passes.m and prog_type.m.

compiler/notes/compiler_design.html:
	Make the documentation of prog_mutable.m easier to read in source.

tests/hard_coded/float_gv.{m,exp}:
	An extended version of Greg's code as a new test case.

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

tests/hard_coded/sub-modules/non_word_mutable.{m,exp}:
tests/hard_coded/sub-modules/non_word_mutable.child.m:
	A version of the float_gv test case in which the compiler-generated
	get and set foreign_procs should end up in .opt files.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/Mercury_options:
	Enable the new test case, and make it execute with intermodule
	optimization.

tests/invalid/bad_mutable.err_exp:
	Expect the new output (in which an error is reported just once,
	not twice).
2006-02-24 01:42:19 +00:00
Zoltan Somogyi
5af71b60ac Remove support for the Aditi backend. It is a pain to have to update it every
Estimated hours taken: 2
Branches: main

Remove support for the Aditi backend. It is a pain to have to update it every
time a data structure changes when we don't see any benefit from it, and its
presence makes compilation of the compiler directory take about 10% longer
(since the Aditi backend modules are roughly 10% of the code in the compiler
directory). Deleting the Aditi-specific data structures from the HLDS should
also speed up compilation a little bit.

I have spoken to Rao and he is fine with this step.

Aditi users, if there are any, can continue to use the Aditi support in
release 0.12.*. I also tagged the last version on the trunk to support aditi
with the name "last_aditi". The need for modifications in this Aditi support
is likely to be very rare to nonexistent, if the recent past is any guide:
the Aditi backend hasn't seen a nontrivial modification in a year or more.

This diff removes a net 31492 lines.

compiler/add_aditi.m:
compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/context.m:
compiler/dnf.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/rl.m:
compiler/rl_analyse.m:
compiler/rl_block.m:
compiler/rl_block_opt.m:
compiler/rl_code.m:
compiler/rl_dump.m:
compiler/rl_exprn.m:
compiler/rl_file.pp:
compiler/rl_gen.m:
compiler/rl_info.m:
compiler/rl_key.m:
compiler/rl_liveness.m:
compiler/rl_loop.m:
compiler/rl_opt.m:
compiler/rl_out.pp:
compiler/rl_relops.m:
compiler/rl_sort.m:
compiler/rl_stream.m:
	Remove these compiler modules, since they existed only to support the
	Aditi backend.

compiler/hlds_goal.m:
	Delete the Aditi-specific components of goals (e.g. the aditi-builtin
	kind of generic calls and Aditi-evaluated lambdas).

compiler/hlds_pred.m:
	Delete the Aditi-specific components of pred_infos.

compiler/prog_data.m:
	Delete the Aditi-specific items.

compiler/passes_aux.m:
	Don't worry about processing all procedures or just all non-Aditi
	procedures.

compiler/add_clause.m:
	Add a predicate from a deleted module that is now used only here.

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

compiler/notes/*.html:
	Remove references to the Aditi backend.

tests/invalid/aditi.m:
tests/invalid/aditi_errors.err_exp:
tests/invalid/aditi_errors.m:
tests/invalid/aditi_private_builtin.m:
tests/invalid/aditi_state_errors.err_exp:
tests/invalid/aditi_state_errors.m:
tests/invalid/aditi_update_derived_relation.err_exp:
tests/invalid/aditi_update_derived_relation.m:
tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_mode_errors.err_exp:
tests/invalid/aditi_update_mode_errors.m:
tests/valid/aditi.m:
tests/valid/aditi_calls_mercury.m:
tests/valid/aditi_error_bug.m:
tests/valid/aditi_error_bug2.m:
tests/valid/aditi_error_bug3.m:
tests/valid/aditi_private_builtin.m:
tests/valid/aditi_query.m:
tests/valid/aditi_update.m:
tests/valid/base_relation.m:
tests/valid/base_relation2.m:
tests/valid/ite_to_disj.m:
	Remove these Aditi-specific tests.

tests/*/Mmakefile:
	Remove the references to these Aditi-specific tests.
2006-02-23 09:37:30 +00:00
Julien Fischer
5af76e31ca Update some comments concerning the recently deleted
Estimated hours taken: 0
Branches: main

compiler/make.m:
compiler/ml_code_gen.m:
compiler/rtti_out.m:
	Update some comments concerning the recently deleted
	--split-c-files option.
2006-01-11 02:33:41 +00:00
Julien Fischer
aca4918747 Make the trail usage analysis less conservative with respect to compiler
Estimated hours taken: 1
Branches: main

Make the trail usage analysis less conservative with respect to compiler
generated special predicates.  This increases the speed of a compiler built in
hlc.gc.tr with --intermodule-optimzation and trail usage analysis by about
3.5% and decreases the executable size by 5.2%.

compiler/trailing_analysis.m:
	Do not assume that type-specific compiler generated unification and
	comparison predicates always modify the trail; some of them, e.g.
	those for enumerations, do not.

	Delete this item from the TODO list.

compiler/mode_info.m:
	Unrelated change: fix indentation in a spot.

compiler/ml_code_gen.m:
	Unrelated change: s/Word/MR_Word/.
2005-12-24 08:44:13 +00:00
Julien Fischer
24ab04569c Update the arity of the high-level data version of type_info and
Estimated hours taken: 1.5
Branches: main

runtime/mercury_hlc_types.h:
	Update the arity of the high-level data version of type_info and
	friends.

library/private_butilin.m:
	Update the arity of type_info etc in some comments and also in the
	assertion messages used by the IL and Java backends.

compiler/ml_code_gen.m:
	Unrelated changed: s/Word/MR_Word/ in a comment.
2005-12-08 06:14:36 +00:00
Julien Fischer
45fdb6c451 Use expect/3 in place of require/2 throughout most of the
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Use expect/3 in place of require/2 throughout most of the
	compiler.

	Use unexpected/2 (or sorry/2) in place of error/1 in more
	places.

	Fix more dodgy assertion error messages.

	s/map(prog_var, mer_type)/vartypes/ where the latter is meant.
2005-11-28 04:11:59 +00:00
Julien Fischer
5f589e98fb Various cleanups for the modules in the compiler directory.
Estimated hours taken: 4
Branches: main

Various cleanups for the modules in the compiler directory.  The are
no changes to algorithms except the replacement of some if-then-elses
that would naturally be switches with switches and the replacement of
most of the calls to error/1.

compiler/*.m:
	Convert calls to error/1 to calls to unexpected/2 or sorry/2 as
	appropriate throughout most or the compiler.

	Fix inaccurate assertion failure messages, e.g. identifying the
	assertion failure as taking place in the wrong module.

	Add :- end_module declarations.

	Fix formatting problems and bring the positioning of comments
	into line with our current coding standards.

	Fix some overlong lines.

	Convert some more modules to 4-space indentation.  Fix some spots
	where previous conversions to 4-space indentation have stuffed
	the formatting of the code up.

	Fix a bunch of typos in comments.

	Use state variables in more places; use library predicates
	from the sv* modules where appropriate.

	Delete unnecessary and duplicate module imports.

	Misc. other small cleanups.
2005-11-17 15:57:34 +00:00
Zoltan Somogyi
f9fe8dcf61 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-10-28 02:11:03 +00:00
Zoltan Somogyi
b2012c0c0e Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8
Branches: main

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

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

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

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

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

	Convert some more modules to four space indentation.

	Avoid excessively long lines, such as those resulting from the
	automatic substitution of 'mer_type' for 'type'.
2005-10-24 04:14:34 +00:00
Zoltan Somogyi
7563cff19e Implement --optimize-constructor-last-call for hlc grades.
Estimated hours taken: 18
Branches: main

Implement --optimize-constructor-last-call for hlc grades.

compiler/lco.m:
	Include the types of pointed-to fields in the types of the address-of
	variables generated by the transformation, since the HLC backend needs
	it.

library/private_builtin.m:
	Add a new type, store_at_ref_type, for use by the new version of the
	transformation in lco.m.

compiler/ml_call_gen.m:
	Handle the form of builtin used by store_at_ref.

compiler/ml_unify_gen.m:
	Handle construction unifications that take the addresses of some
	fields.

compiler/ml_closure_gen.m:
	Conform to the change in ml_unify_gen.m.

compiler/handle_options.m:
	Do not disable --optimize-constructor-last-call in hlc grades.

compiler/add_pred.m:
	When creating the implementation of the store_at_ref builtin,
	don't make the body of the predicate be an invocation of the builtin
	itself, since the generated HLC code is not type-correct C. Instead,
	make it "true". Since the predicate itself (as distinct from the
	builtin operation) is never used, this is OK.

	Minor cleanups.

compiler/mlds_to_c.m:
	Make the generated C code somewhat easier to read.

	Convert to four-space indentation.

compiler/options.m:
	Add an option, opt_level_number, which records the selected
	optimization level numerically. The idea is that optimizations such
	as --optimize-constructor-last-call, which produce speedups only
	at some but not all optimization levels, can be enabled only when
	they help. This capability is not yet used; that will require further
	experimentation.

	Convert to four-space indentation.

compiler/mlds.m:
	Translate store_at_ref Mercury types into a pointer MLDS type.

	Minor cleanups.

compiler/ml_code_gen.m:
compiler/ml_code_util.m:
	Minor cleanups.
2005-10-17 07:43:28 +00:00
Zoltan Somogyi
d609181cb9 Consider types of the form
Estimated hours taken: 30
Branches: main

Consider types of the form

	:- type x ---> f.

to be dummy types, since they contain no information. Optimize them the same
way we currently optimize io.state and store.store.

runtime/mercury_type_info.h:
	Add a new type_ctor_rep for dummy types.

runtime/mercury_tabling.h:
	Add a representation for "tabled" dummy types, which don't actually
	have a level in the trie, so that the runtime system can handle that
	fact.

runtime/mercury_ml_expand_body.h:
	When deconstructing a value of a dummy type, ignore the actual value
	(since it will contain garbage) and instead return the only possible
	value of the type.

runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.c:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
library/rtti_implementation.m:
	Handle the type_ctor_rep of dummy types.

runtime/mercury_builtin_types.c:
	Provide a place to record profiling information about unifications and
	comparisons for dummy types.

runtime/mercury_mcpp.h:
java/runtime/TypeCtorRep.java:
library/private_builtin.m:
	Add a new type_ctor_rep for dummy types, and fix some previous
	discrepancies in type_ctor_reps.

mdbcomp/prim_data.m:
	Move a bunch of predicates for manipulating special_pred_ids here from
	the browser and compiler directories.

	Rename the function symbols of the special_pred_id type to avoid the
	need to parenthesize the old `initialise' function symbol.

	Convert to four-space indentation.

mdbcomp/rtti_access.m:
	Don't hardcode the names of special preds: use the predicates in
	prim_data.m.

	Convert to four-space indentation.

browser/declarative_execution.m:
	Delete some predicates whose functionality is now in
	mdbcomp/prim_data.m.

compiler/hlds_data.m:
	Replace the part of du type that says whether a type an enum, which
	used to be a bool, with something that also says whether the type is a
	dummy type.

	Convert to four-space indentation.

compiler/make_tags.m:
	Compute the value for the new field of du type definitions.

compiler/hlds_out.m:
	Write out the new field of du type definitions.

compiler/rtti.m:
	Modify the data structures we use to create type_ctor_infos to allow
	for dummy types.

	Convert to four-space indentation.

compiler/type_ctor_info.m:
	Modify the code that generates type_ctor_infos to handle dummy types.

compiler/type_util.m:
	Provide predicates for recognizing dummy types.

	Convert to four-space indentation.

compiler/unify_proc.m:
	Generate the unify and compare predicates of dummy types using a new
	code scheme that avoids referencing arguments that contain garbage.

	When generating code for unifying or comparing other types, ignore
	any arguments of function symbols that are dummy types.

	Don't use DCG style access predicates.

compiler/higher_order.m:
	Specialize the unification and comparison of values of dummy types.

	Break up an excessively large predicate, and factor out common code
	from the conditions of a chain of if-then-elses.

compiler/llds.m:
	For each input and output of a foreign_proc, include a field saying
	whether the value is of a dummy type.

compiler/pragma_c_gen.m:
	Fill in the new fields in foreign_proc arguments.

compiler/hlds_goal.m:
	Rename some predicates for constructing unifications to avoid
	unnecessary ad-hoc overloading. Clarify their documentation.

	Rename a predicate to make clear the restriction on its use,
	and document the restriction.

	Add a predicate for creating simple tests.

	Add a utility predicate for setting the context of a goal directly.

compiler/modules.m:
	Include dummy types interface files, even if they are private to the
	module. This is necessary because with the MLDS backend, the generated
	code inside the module and outside the module must agree whether a
	function returning a value of the type returns a real value or a void
	value, and this requires them to agree on whether the type is dummy
	or not.

	The impact on interface files is minimal, since very few types are
	dummy types, and changing a type from a dummy type to a non-dummy type
	or vice versa is an ever rarer change.

compiler/hlds_pred.m:
	Provide a representation in the compiler of the trie step for dummy
	types.

compiler/layout_out.m:
	Print the trie step for dummy types.

compiler/table_gen.m:
	Don't table values of dummy types, and record the fact that we don't
	by including a dummy trie step in the list of trie steps.

compiler/add_pragma.m:
compiler/add_special_pred.m:
compiler/add_type.m:
compiler/aditi_builtin_ops.m:
compiler/bytecode.m:
compiler/bytecode_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/cse_detection.m:
compiler/det_report.m:
compiler/exception_analysis.m:
compiler/inst_match.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_il.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/opt_util.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/qual_info.m:
compiler/rl.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/rtti_out.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/term_constr_initial.m:
compiler/term_constr_util.m:
compiler/term_norm.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_gen.m:
	Conform to the changes above.

compiler/export.m:
compiler/exprn_aux.m:
compiler/foreign.m:
compiler/polymorphism.m:
compiler/proc_label.m:
compiler/rtti_to_mlds.m:
compiler/special_pred.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/state_var.m:
compiler/switch_util.m:
compiler/trace_params.m:
	Conform to the changes above.

	Convert to four-space indentation.

compiler/mlds_to_java.m:
compiler/var_locn.m:
	Conform to the changes above, which requires threading the module_info
	through the module.

	Convert to four-space indentation.

compiler/mercury_compile.m:
	Pass the module_info to mlds_to_java.m.

compiler/ml_util.m:
compiler/polymorphism.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
	Delete some previously missed references to the temporary types used
	to bootstrap the change to the type_info type's arity.

compiler/polymorphism.m:
	Turn back on an optimization that avoids passing parameters (such as
	type_infos) to foreign_procs if they are not actually referred to.

compiler/prog_data.m:
	Convert to four-space indentation.

library/svvarset.m:
	Add a missing predicate.

trace/mercury_trace.c:
	Delete the unused function that used to check for dummy types.

tests/debugger/field_names.{m,inp,exp}:
	Add to this test case a test of the handling of dummy types. Check that
	their values can be printed out during normal execution, and that the
	debugger doesn't consider them live nondummy variables, just as it
	doesn't consider I/O states live nondummy variables.
2005-10-05 06:34:27 +00:00
Zoltan Somogyi
b54ab42d70 A simple tool for performing substitutions on the source files of the
Estimated hours taken: 0.5
Branches: main

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

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

s/module_info_types/module_info_get_type_table/
s/module_info_set_types/module_info_set_type_table/
s/module_info_insts/module_info_get_inst_table/
s/module_info_set_insts/module_info_set_inst_table/
s/module_info_modes/module_info_get_mode_table/
s/module_info_set_modes/module_info_set_mode_table/
s/module_info_ctors/module_info_get_cons_table/
s/module_info_set_ctors/module_info_set_cons_table/
s/module_info_classes/module_info_get_class_table/
s/module_info_set_classes/module_info_set_class_table/
s/module_info_instances/module_info_get_instance_table/
s/module_info_set_instances/module_info_set_instance_table/
s/module_info_superclasses/module_info_get_superclass_table/
s/module_info_set_superclasses/module_info_set_superclass_table/
s/module_info_assertion_table/module_info_get_assertion_table/
s/module_info_exclusive_table/module_info_get_exclusive_table/
s/module_info_ctor_field_table/module_info_get_ctor_field_table/
s/module_info_name/module_info_get_name/
s/module_info_globals/module_info_get_globals/
s/module_info_contains_foreign_types/module_info_get_contains_foreign_types/
s/module_info_num_errors/module_info_get_num_errors/
s/module_info_type_ctor_gen_infos/module_info_get_type_ctor_gen_infos/
s/module_info_stratified_preds/module_info_get_stratified_preds/
s/module_info_unused_arg_info/module_info_get_unused_arg_info/
s/module_info_exception_info/module_info_get_exception_info/
s/module_info_type_spec_info/module_info_get_type_spec_info/
s/module_info_no_tag_types/module_info_get_no_tag_types/
s/module_info_analysis_info/module_info_get_analysis_info/
s/module_info_aditi_top_down_procs/module_info_get_aditi_top_down_procs/
2005-09-30 08:08:49 +00:00
Julien Fischer
f57fe1b7df Add language and compiler support for finalise declarations.
Estimated hours taken: 8
Branches: main

Add language and compiler support for finalise declarations.

NEWS:
	Mention finalise declarations.

compiler/prog_data.m:
	Add a new item type for finalise declarations.

	Add a new kind of item origin - items can now be introduced as part of
	the source-to-source transformation that implements finalise
	declarations.

compiler/prog_io.m:
	Parse finalise declarations.

compiler/modules.m:
	Don't write out finalise declarations in private interfaces.

compiler/hlds_module.m:
	Add a slot to the HLDS that stores the names of the predicates in
	finalise declarations.

	Add access predicates for the above.

compiler/add_pragma.m:
compiler/make_hlds_passes.m:
	Fix in incorrect comment: we add initialise declarations on third, not
	second, pass.

	Restore the code that use the enhanced switch detection capability.

	Implement the source-to-source transformation that implements finalise
	declarations.  This is almost identical to that for intitialise
	declarations.

compiler/llds.m:
compiler/llds_out.m:
compiler/transform_llds.m:
	Add a slot to the LLDS to hold the name of the predicates specified in
	the finalise declarations.

	Emit the necessary code to call these predicates after main has finished.

compiler/mlds.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
	As above, but for the MLDS.

compiler/mercury_compile.m:
	Conform to changes in the MLDS.
	XXX This module probably shouldn't manipulating the MLDS directly.

compiler/module_qual.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Conform to the above changes.

library/ops.m:
	Add `finalise' as an operator.

runtime/mercury_wrapper.c:
	Call any user specified finalise predicates from
	mercury_runtime_terminate.

doc/reference_manual.texi:
	Document finalise declarations.

tests/hard_coded/Mmakefile:
tests/hard_coded/finalise_decl.m:
tests/hard_coded/finalise_decl.exp:
	Tests finalise declarations.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/finalise_child.m:
tests/hard_coded/sub-modules/finalise_parent.m:
tests/hard_coded/sub-modules/finalise_parent.{exp,exp2}:
	Test finalise declarations and sub-modules.  There are two expected
	outputs because the order of execution between a parent module and its
	children of any finalisers is arbitrary.

tests/invalid/Mmakefile:
tests/invalid/bad_finalise_decl.m:
tests/invalid/bad_finalise_decl.err_exp:
	Test error messages associated with finalise declarations.
2005-09-29 06:33:17 +00:00
Julien Fischer
cdf9ccf352 Use promise_equivalent_solutions scopes in place of
Estimated hours taken: 0.5
Branches: main

compiler/assertion.m:
compiler/magic.m:
compiler/mercury_compile.m:
compiler/ml_code_gen.m:
compiler/modes.m:
compiler/modules.m:
compiler/options_file.m:
compiler/recompilation.check.m:
compiler/recompiltaion.usage.m:
	Use promise_equivalent_solutions scopes in place of
	promise_only_solution and promise_only_solution_io in the compiler.
2005-09-26 05:48:10 +00:00
Zoltan Somogyi
45aa3aad8a Convert these modules to four space indentation, and clean up
Estimated hours taken: 2
Branches: main

compiler/ml_*.m:
	Convert these modules to four space indentation, and clean up
	departures from our coding standards.
2005-09-13 01:19:57 +00:00
Mark Brown
3fc6b3f128 Change the representation of types in the compiler.
Estimated hours taken: 30
Branches: main

Change the representation of types in the compiler.

We also add some support for handling kinds, which will be used later when we
have a kind system.  There are a number of places where kinds are not yet
handled correctly -- we assume that all kinds will be `star'.  Each of these
locations is flagged with a comment that contains "XXX kind inference:".


compiler/prog_data.m:
	Implement the new version of type (type).

	Change the definition of type_param to be a variable instead of a
	term, since all parameters must be variables anyway.

	Implement versions of varset.merge_* which work with tvarsets and
	produce renamings instead of substitutions.  Renamings are more
	convenient than substitutions because we don't need to know the
	kinds of type variables in order to build the renaming, and in any
	case the substitutions shouldn't have anything other than variables
	in the range so renamings will be more efficient and safe.

	Define the type of kinds, and provide a couple of utility predicates
	to operate on them.

compiler/prog_io.m:
	Parse type definition heads as a sym_name and list of type_params,
	rather than a functor.  Handle this change in other predicates.

	Allow parse errors to be returned by get_with_type/3, and handle
	these errors.

	Remove parse_type/2.  This predicate didn't do any processing, it
	just forwarded handling to convert_type/2.

compiler/prog_io_typeclass.m:
	Change type_is_functor_and_vars to handle the new representation
	of types.  In doing so, we retain the old behaviour that pure
	predicates pass this test, but no other pred or func types.  This
	behaviour is arguably incorrect, but there is little point changing
	the behaviour at the moment.  Instead we should remove these kind of
	restrictions entirely, but that should be done later.

compiler/prog_io_util.m:
	Provide predicates to both parse and unparse types.  We need to
	unparse types before printing them out, since we do a lot of special
	case handling when printing out terms and we don't want to duplicate
	this functionality for types.

compiler/module_qual.m:
	Remove report_invalid_type.  We now report ill-formed types during
	parsing.

compiler/superhomogeneous.m:
	Handle errors from the parsing of type expressions.

compiler/prog_out.m:
	Provide a predicate to convert builtin_types to their string names,
	and vice-versa.

compiler/prog_type.m:
	Add a bunch of simple tests to use on types which may have kind
	annotations present.  In such cases, types do not have a canonical
	representation so the simple handling of these tests is not what we
	want.  (Note that these are only required in early phases.  The kind
	annotations -- when they are implemented -- will be removed before
	type checking.)

	Consistently handle the application of renamings, substitutions and
	recursive substitutions to various data structures.

compiler/mercury_to_mercury.m:
	Implement mercury_output_type, mercury_format_type and
	mercury_type_to_string.  These convert the type to a term before
	formatting -- the reason for this is so that appropriate parentheses
	are used when formatting operators.  This results in some slight
	changes to error messages, which are reflected in changes to the
	expected output files in the tests.

	Remove the old version of mercury_type_to_string.

	Change the argument ordering of mercury_format_var to be consistent
	with mercury_format_type.  (Other predicates in this module should
	probably be changed in a similar way, since this argument ordering
	is more amenable to higher-order programming.  But that can be left
	for another change.)

compiler/type_util.m:
	Implement type unification.  The behaviour is much the same as the
	previous behaviour, except that we now handle apply/N types properly,
	and we also allow for kind annotations.

	Implement an occurs check for types.

	Remove the example definition of replace_eqv_type.  It isn't used and
	would no longer work anyway even if it would have worked before.

	Add a tvar_kind_map field to ctor_defn.

	The functions type_info_type and type_ctor_info_type now return
	types with `void' as their argument, rather than the type that the
	type_info or type_ctor_info was for.

	Remove type_util.real_vars/2, since it no longer does anything
	different from prog_type.vars/2.

	Remove the commented out implementation of type_to_ctor_and_args/3.
	Its implementation is in prog_type.m, and has changed significantly
	in any case.

compiler/add_clause.m:
	Move parse_purity_annotation/3 to prog_io_util.m.

compiler/check_typeclass.m:
	Remove apply_substitution_to_var_list/3, since we now have predicates
	in prog_type.m to handle such things.

compiler/continuation_info.m:
compiler/trace.m:
	Use prog_type.vars/2 instead of type_util.real_vars/2.  The two
	predicates have the same meaning now since type_infos don't contain
	any type variables.

compiler/hlds_data.m:
	Add tvar_kind_map fields to hlds_type_defn and hlds_class_defn.

compiler/hlds_pred.m:
	Add a tvar_kind_map field to pred_info.

compiler/polymorphism.m:
	Add a tvar_kind_map field to poly_info.

	Remove unify_corresponding_types, which is no longer used.

compiler/hlds_out.m:
	Use mercury_output_type/5 instead of term_io__write_term/4 and
	mercury_output_term/5.

compiler/post_typecheck.m:
	Build the void substitution directly rather than building intermediate
	lists.

compiler/recompilation.version.m:
	Use term__list_subsumes instead of type_list_subsumes, which now
	operates only on types.  This follows up on what was suggested in
	an XXX comment.

compiler/typecheck_errors.m:
	Use unparse_type/2 to format error messages.

compiler/typecheck_info.m:
	Don't export write_type_with_bindings/5.  It is no longer used
	outside of this module.

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

library/rtti_implementation.m:
	Fix a syntax error that went undetected in our previous
	implementation, and amazingly enough was compiled correctly anyway.

library/term.m:
	Move the versions of term__unify, term__unify_list and
	term__list_subsumes that were implemented specifically for types
	to here.  The version of term_unify that takes a list of bound
	variables (i.e., variables that should not be bound any further)
	is used by the subsumption check, which in turn is used by
	recompilation.version.m.

tests/invalid/kind.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/misc_tests/pretty_print_test.exp:
	Update the expected output of these tests to match what we now do.
2005-09-12 05:25:01 +00:00
Julien Fischer
6634a3dfc2 Implement initialise declarations for the high-level C backend.
Estimated hours taken: 1.5
Branches: main

Implement initialise declarations for the high-level C backend.

compiler/mlds.m:
	Add a slot to the MLDS to hold the name of module intialisation
	predicates.

	XXX We should use a higher level representation of the names
	here in case we need to treat them differently in the other
	target languages.

compiler/mlds_to_c.m:
	Output the necessary INIT and REQUIRED_INIT comments.

compiler/mercury_compile.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
	Handle the extra field in the MLDS.

compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/mlds_to_gcc.m:
	Handle the extra field in the MLDS.  We don't
	yet support initialise declarations on these backends.
2005-09-01 09:06:35 +00:00
Zoltan Somogyi
6df9a05856 This diff cleans up a bunch of modules. It has no algorithmic changes
Estimated hours taken: 10
Branches: main

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

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

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

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

	Conform to the changed argument order above.

	Use suffixes instead of append_punctuation.

library/string.m:
	Add string.foldl2.

tests/invalid/circ_*.err_exp:
tests/warnings/unused_args_*.exp:
	Expect the updated error messages, which format sym_names consistently
	the same way as other messages.
2005-08-30 04:12:17 +00:00
Zoltan Somogyi
2f06c5b8fe Don't just detect when successive unifications unify the same variable with
Estimated hours taken: 6
Branches: main

Don't just detect when successive unifications unify the same variable with
incompatible function symbols: also issue a warning.

compiler/ml_code_gen.m:
compiler/stratify.m:
compiler/table_gen.m:
mdbcomp/trace_counts.m:
	Fix pieces of code that get the new warning.

compiler/modecheck_unify.m:
	When detecting such unifications, add warnings for them, except if
	the initial inst of the current restricts the set of allowed bindings
	of the input arguments. If the initial inst of X is bound(f), then
	an otherwise correct unification Y = g may fail if Y has been computed
	from X. (We don't whether it has, so we have to be conservative.)
	There are examples of such code in the library, e.g. functor in
	deconstruct.m.

	Factor out some common code.

compiler/mode_errors.m:
	Add the infrastructure needed for printing warnings, and the two forms
	of this warning in particular.

compiler/mode_info.m:
	Extend the mode_info structure to make room for warnings, and for the
	initial inst of the procedure arguments.

	Switch to four-space indentation.

compiler/inst_util.m:
	Add a predicate that tests whether an inst may restrict the set of
	possible cons_ids a variable may be bound to.

	Change the argument order of some predicates to allow them to be
	used in higher order code. We don't need to make the switched-on
	argument the first argument anymore.

	Switch to four-space indentation.

compiler/hlds_goal.m:
	Change the argument order of some predicates to allow the use of state
	variables.

compiler/higher_order.m:
compiler/instmap.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/trace.m:
	Conform to the changed argument orders described above.

	Switch to four-space indentation.

compiler/common.m:
compiler/inst_match.m:
compiler/hlds_pred.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/post_typecheck.m:
compiler/unique_modes.m:
	Conform to the changed argument orders described above.

tests/invalid/occurs.err_exp:
	Expect the extra warning.

tests/warnings/Mmakefile:
	Enable the unify_f_g test case I accidentally committed earlier.

tests/warnings/unify_f_g.{m,err_exp}:
	Finalize that test case.

tests/warnings/simple_code.err_exp:
	Expect the extra warning.
2005-08-27 09:42:10 +00:00
Julien Fischer
bdb50b33ce Break the cycle in the package dependency graph between the
Estimated hours taken: 1
Branches: main

Break the cycle in the package dependency graph between the
hlds and backend_libs packages by moving yet more of the
contents of the foreign module into the new prog_foreign
module.  There are no changes to any code other than
moving it around.

compiler/foreign.m:
compiler/prog_foreign.m:
	Shift most of the types related to the foreign language
	interface into the latter module.

	Fix a typo in a comment at the beginning of prog_foreign.m.

	Clean up the formatting of comments in foreign.m.

compiler/hlds.m:
	Update the comment about why the transform_hlds package
	is imported here.

compiler/*.m:
	Minor changes caused by the above.
2005-03-24 13:33:34 +00:00
Zoltan Somogyi
8b8b3b7d3f Replace the some() HLDS goal with a more general scope() goal, which can be
Estimated hours taken: 12
Branches: main

Replace the some() HLDS goal with a more general scope() goal, which can be
used not just for existential quantification but also for other purposes.

The main such purposes are new goal types that allow the programmer
to annotate arbitrary goals, and not just whole procedure bodies, with the
equivalents of promise_pure/promise_semipure and promise_only_solution:

	promise_pure ( <impure/semipure goal> )
	promise_semipure ( <impure goal> )

	promise_equivalent_solutions [OutVar1, OutVar2] (
		<cc_multi/cc_nondet goal that computed OutVar1 & OutVar2>
	)

Both are intended to be helpful in writing constraint solvers, as well as in
other situations.

doc/reference_manual.texi:
	Document the new constructs.

library/ops.m:
	Add the keywords of the new constructs to the list of operators.
	Since they work similarly to the "some" operator, they have the same
	precedence.

compiler/hlds_goal.m:
	Replace the some(Vars, SubGoal) HLDS construct, with its optional
	keep_this_commit attribute, with the new scope(Reason, SubGoal)
	construct. The Reason argument may say that this scope is an
	existential quantification, but it can also say that it represents
	a purity promise, the introduction of a single-solution context
	with promise_equivalent_solutions, or a decision by a compiler pass.

	It can also say that the scope represents a set of goals that all arise
	from the unraveling of a unification between a variable and a ground
	term. This was intended to speed up mode checking by significantly
	reducing the number of delays and wakeups, but the cost of the scopes
	themselves turned out to be bigger than the gain in modechecking speed.

	Update the goal_path_step type to refer to scope goals instead of just
	existential quantification.

compiler/prog_data.m:
	Add new function symbols to the type we use to represent goals in items
	to stand for the new Mercury constructs.

compiler/prog_io_goal.m:
	Add code to read in the new language constructs.

compiler/prog_io_util.m:
	Add a utility predicate for use by the new code in prog_io_goal.m.

compiler/make_hlds.m:
	Convert the item representation of the new constructs to the HLDS
	representation.

	Document how the from_ground_term scope reason would work, but do not
	enable the code.

compiler/purity.m:
	When checking the purity of goals, respect the new promise_pure and
	promise_semipure scopes. Generate warnings if such scopes are
	redundant.

compiler/det_analysis.m:
	Make the insides of promise_equivalent_solutions goals single solution
	contexts.

compiler/det_report.m:
	Provide mechanisms for reporting inappropriate usage of
	promise_equivalent_solutions goals.

compiler/instmap.m:
	Add a utility predicate for use by one of the modules above.

compiler/deep_profiling.m:
	Use one of the new scope reasons to prevent simplify from optimizing
	away commits of goals that have been made impure, instead of the old
	keep_this_commit goal feature.

compiler/modes.m:
	Handle from_ground_term scopes when present; for now, they won't be
	present, since make_hlds isn't creating them.

compiler/options.m:
	Add two new compiler options, for use by implementors only, to allow
	finer control over the amount of output one gets with --debug-modes.
	(I used them when debugging the performance of the from_ground_term
	scope reason.) The options are --debug-modes-minimal and
	--debug-modes-verbose.

compiler/handle_options.m:
	Make the options that are meaningful only in the presence of
	--debug-modes imply --debug-modes, since this allows more convenient
	(shorter) invocations.

compiler/mode_debug.m:
	Respect the new options when deciding how much data to print
	when debugging of the mode checking process is enabled.

compiler/switch_detect.m:
	Rename a predicate to make it differ from another predicate by more
	than just its arity.

compiler/passes_aux.m:
	Bring this module up to date with our current style guidelines,
	by using state variable syntax where appropriate.

compiler/*.m:
	Minor changes to conform to the change in the HLDS and/or parse tree
	goal type.

mdbcomp/program_representation.m:
	Rename the some goal to the scope goal, and the same for path steps,
	to keep them in sync with the HLDS.

browser/declarative_tree.m:
	Conform to the change in goal representations.

tests/hard_coded/promise_equivalent_solutions_test.{m,exp}:
	A new test case to test the handling of the
	promise_equivalent_solutions construct.

tests/hard_coded/Mmakefile:
	Enable the new test.

tests/hard_coded/purity/promise_pure_test.{m,exp}:
	A new test case to test the handling of the promise_pure and
	promise_semipure constructs.

tests/hard_coded/purity/Mmakefile:
	Enable the new test.

tests/invalid/promise_equivalent_solutions.{m,err_exp}:
	A new test case to test the error messages for improper use of the
	promise_pure and promise_semipure constructs.

tests/invalid/Mmakefile:
	Enable the new test.
2005-03-24 05:34:41 +00:00
Zoltan Somogyi
3c60c0e485 Change a bunch of modules to import only one module per line, even
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Change a bunch of modules to import only one module per line, even
	from the library.

compiler/mlds_to_il.m:
compiler/mlds_to_managed.m:
	Convert these modules to our current coding style. Use state variables
	where appropriate. Use predmode declarations where possible.
2005-03-22 06:40:32 +00:00
Zoltan Somogyi
99af5e671a Provide a mechanism to allow a predicate to be defined as a foreign_proc for
Estimated hours taken: 10
Branches: main

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

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

	:- external(high_level_backend, p/3).

The second allows foreign_procs such as

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

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

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

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

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

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

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

compiler/hlds_module.m:
	Clean up some formatting.

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

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

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

tests/hard_coded/Mmakefile:
	Enable the new test case.
2005-03-10 02:36:04 +00:00
Julien Fischer
a3352a6e5d Do not include :- import_module' and :- use_module' declarations
Estimated hours taken: 22
Branches: main

Do not include `:- import_module' and `:- use_module' declarations
in the implementation section of .int and .int2 files unless
the types that they export are required by the definition of
an equivalence type.  This should help prevent unnecessary
recompilations when new imports are made in the implementation
of modules.

Break up check_hlds.type_util so that predicates that do
not require access to the HLDS are placed in a new module,
parse_tree.prog_type.  The above change requires some of
these predicates.  This also removes one of the dependencies
between the parse_tree package on modules of the check_hlds
package.

Remove the remaining such dependency by moving
inst_constrains_unconstrained_var/1 from check_hlds.inst_util
to parse_tree.prog_mode.  None of the modules in parse_tree
now depend upon modules in check_hlds.

Modify the parser so that import_module declarations
that specify more than one module are replaced by multiple
import_module declarations, with one module per declaration.
This makes the above change easier to implement and is in
any case required by the upcoming diff for canonicalizing
module interfaces.  We also do the same for use_module and
include_module declarations.

compiler/modules.m:
	Don't import modules in the implementation section
	of interface files unless they are required by the
	definition of equivalence types.

compiler/prog_type.m:
	New module.  Move procedures from type_util that do
	not depend on the HLDS to here so that we can use them
	when generating interface files.

	XXX There are probably others that could be moved as
	well - I only moved those that were immediately useful.

compiler/type_util.m:
	Delete the procedures that have been moved to the
	new prog_type module.

compiler/prog_io.m:
	Remove the dependency on check_hlds.inst_util.

compiler/prog_io_typeclass.m:
compiler/equiv_type.m:
	Remove dependencies on check_hlds.type_util.

compiler/prog_util.m:
	Add a predicate sym_name_get_module_name/2 that is
	similar to sym_name_get_module_name/3 except that it
	fails if the input is an unqualified sym_name.

compiler/inst_util.m:
	Delete inst_contains_unconstrained_var/1 from this
	module and copy it to prog_mode.m.

compiler/parse_tree.m:
	Include the new module.

	Do not import the check_hlds package as all dependencies
	on this package have been removed.

compiler/*.m:
	Minor changes to conform to the above.

compiler/notes/compiler_design.html:
	Mention the new module.
2005-01-21 03:27:58 +00:00
Peter Wang
59d2d4a573 This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17
Branches: main

This adds a module mdbcomp__trace_counts that reads in the
.mercury_trace_counts files produced by the compiler's trace mechanism.
The format of said files was slightly changed.

As the new module is to be used by the compiler and the debugger, it is
placed in the mdbcomp module.  This required bringing some types from the
compiler into a new module within mdbcomp.

browser/trace_counts.m:
	New module for reading execution trace summaries.

browser/prim_data.m:
	New module holding types and predicates moved in from the compiler.
	Types:
		pred_or_func, sym_name, module_name, proc_label,
		special_pred_id, trace_port
	Predicates:
		string_to_sym_name, insert_module_qualifier

	The mode field of proc_label is now an int instead of a proc_id
	to avoid pulling proc_id into mdbcomp.

browser/mdbcomp.m:
	Add trace_counts and prim_data to the mdbcomp module.

browser/declarative_execution.m:
	Renamed mdb's definition of module_name to flat_module_name
	to avoid conflicts with the definition in mdbcomp__prim_data.

runtime/mercury_trace_base.c:
	In the format of .mercury_trace_counts, write module and predicate
	names now use quoted atom syntax so that names with spaces and
	non-printable characters can be machine-parsed.

browser/:
compiler/:
	Many changes to account for movement of types, and the change to
	proc_label.
2005-01-19 03:11:22 +00:00
Ralph Becket
bf2e37d199 Implemented the solver types design.
Estimated hours taken: 100s
Branches: main

Implemented the solver types design.

Solver types provide the means for adding constrained types to Mercury
programs.  A variable of a constrained type may have constraints placed
on it, limiting the values it may be bound to, *before* the variable is
actually bound to a particular value (cf. CLP(Z), CLP(R), CLP(FD) etc.)

Improve the scheduling of solver type goals by preferring deconstructions
over constructions followed by unifications.  This is arranged by allowing
solver type initialisation calls to be inserted only when all else fails.
(XXX This implementation is O(n^2).  I will fix things if this becomes an
issue in practice.)

I have also made some small, opportunistic cosmetic changes.  This
implementation has evolved through several design changes, during which some
functionality was added then later removed - I elected to preserve any
cleaned-up replacement code if removing the no-longer-needed-by-the-
solver-types-design functionality was easy to do.

doc/reference_manual.texi:
	Document solver types.

compiler/hlds_data.m:
	Changed the du_type and foreign_type constructors appropriately
	and added a new solver_type constructor.

compiler/hlds_out.m:
	Improved the code to write out the `where ...' part of
	a type definition and moved it to mercury_output.m.

compiler/inst_match.m:
	Added the pred inst_is_any/1.

compiler/inst_util.m:
	Added the pred inst_contains_unconstrained_var/1.

compiler/make_hlds.m:
	Added processing for solver types, in particular adding the
	compiler generated declarations and implementations of the
	conversion functions.

compiler/mercury_to_mercury.m:
	Added predicate mercury_output_where_attributes.

compiler/mode_info.m:
	Added a new field to mode_info to indicate whether solver type
	initialisation calls can be inserted by modecheck_conj_list_2.

compiler/mode_errors.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
	The compiler now inserts calls to initialisation preds, where
	necessary, before calls and at the end of procedures.  It does
	not yet do this at the end of disjuncts and its scheduling
	policy is naive (i.e. it performs terribly.)

	Added modecheck_conj_list_3 which allows modecheck_conj_list_2
	to insert initialisation calls for a single goal, then repeats
	if this succeeded in scheduling some delayed goals.

compiler/modules.m:
	XXX Reviewers: please look at the `rafe: XXX' comments and
	advise!

compiler/prog_data.m:
	Added the solver_type constructor and the special_type_details
	and solver_type_details types.

compiler/prog_io.m:
compiler/prog_io_pragma.m:
	Parse the new syntax.
	Replaced get_maybe_equality_compare_preds with
	parse_type_decl_where_part_if_present.

compiler/prog_mode.m:
	Added funcs in_mode/1, out_mode/1, in_any_mode/0,
	out_any_mode/0, and any_inst/0.

compiler/special_pred.m:
	Added `initialise' constructor to special_pred_id.
	Changed special_pred_name to include the type name and arity
	with `__Unify__', `__Inex__' etc.

compiler/type_util.m:
	Added some more utility funcs/preds.

compiler/unify_proc.m:
	Generate the forwarding predicates for initialisation preds.

compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/module_qual.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/rl_key.m:
compiler/table_gen.m:
compiler/term_norm.m:
compiler/termination.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
	Propagate the changes to hlds_goal_expr.
2004-09-05 23:52:54 +00:00
Fergus Henderson
d0228c4489 Some work towards getting the "browser" directory to build in grade java.
Estimated hours taken: 24
Branches: main

Some work towards getting the "browser" directory to build in grade java.

In particular, this is a step towards fixing a problem in the Java
back-end with sub-modules.  When compiling code that uses sub-modules,
we run up against a Java restriction that a class which is in a package
is not allowed to have the same name as the package.  The work-around
is to use names starting with an uppercase letter for Java class names,
and names starting with a lower-case letter for Java package names.

XXX This diff is a partial step: it uses names starting with an
uppercase letter for Java class names that correspond to Mercury types.
It does not yet use an uppercase letter for Java classes that correspond
to Mercury modules.

XXX With this diff, we just flip the case of the initial letter,
which just works around the problem by avoiding the clashing cases,
rather than eliminating them.  We should use a more complicated mangling
that eliminates the problem completely, e.g. map lowercase Mercury names
to uppercase, map uppercase Mercury names to "U_" followed by the name.

compiler/mlds_to_java.m:
	Output type names with an initial uppercase letter.

compiler/mlds.m:
	Add a new enumeration type qual_kind, with values type_qual
	and module_qual.
	Add a qual_kind field to the fully_qualified_type type.
	Add a qual_kind argument to the append_class_qualifier function,
	and if the qual_kind is module_qual, adjust the case of the
	qualifier appropriately for the back-end.

compiler/ml*.m:
compiler/rtti_to_mlds.m:
	Fill in the new qual_kind field, and pass qual_kind to
	append_class_qualifier.

library/builtin.m:
library/private_builtin.m:
library/type_desc.m:
library/io.m:
library/rtti_implementation.m:
	Use type names with an initial uppercase letter.

browser/Mmakefile:
	Work around problems where Java compilers don't like the file names
	generated by mmc for code using sub-modules.

	For IL and Java, build with --allow-stubs --no-warn-stubs.

browser/declarative_execution.m:
	Give a Java definition for the "proc_layout" type.
	This is needed to avoid compilation errors in grade java.
2004-08-02 08:30:17 +00:00
Zoltan Somogyi
bf0a828169 Provide a mechanism for working around a problem with the Java implementation
Estimated hours taken: 1
Branches: main

Provide a mechanism for working around a problem with the Java implementation
of the nondet and multi modes of catch_impl in exception.m. The workaround
is not intended to be a long term solution.

compiler/ml_code_gen.m:
	Allow ordinary foreign_procs for nondet and multi procedures
	if they have the new foreign_proc attribute ordinary_despite_detism.

compiler/prog_data.m:
	Add the new attribute.

compiler/prog_io_pragma.m:
	Parse the new attribute.
2004-07-06 04:18:50 +00:00
Zoltan Somogyi
397c00af51 Fix the failure of the tabling/unused_args test case in grade hlc.gc.
Estimated hours taken: 3
Branches: main

Fix the failure of the tabling/unused_args test case in grade hlc.gc. The root
cause of the failure was that the MLDS backend used the same template for
generating code for foreign_procs with determinism failure as it did for
foreign_procs with determinism semidet and cc_multi. The former aren't
supposed to assign to SUCCESS_INDICATOR, since their success is not in doubt,
but the code template assumed they did, and tested the value of this undefined
variable.

The manifestation of this error was that the predicate mark_as_failed in
table_builtin.m had an undefined success value.

Also, improve performance by passing foreign types as Mercury types if they
have the can_pass_as_mercury_type assertion.

compiler/ml_code_gen.m:
	Fix this error for the MLDS C backend, and put a XXX next to the
	relevant code for the other MLDS backends.

	Pass foreign types with the can_pass_as_mercury_type assertion as
	Mercury types.

compiler/foreign.m:
	In the data structure recording information about foreign types,
	record not only their names but also the assertions about them.
	Return this extra information in the outputs of the relevant
	predicates, for use in ml_code_gen.m.

	Remove module qualifications from predicate names, since the
	inconsistencies between predicate declarations and definitions
	(some had module qualifications, some didn't) were confusing mtags.

compiler/export.m:
	Minor diffs to conform to the changed interface of foreign.m.

tests/tabling/unused_argument.{m,exp}*:
	Make this test case tougher by testing not just unused arguments,
	but also a tabled predicate without inputs (which are handled specially
	in table_gen.m).
2004-06-17 04:18:28 +00:00
Zoltan Somogyi
885fd4a387 Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12
Branches: main

Remove almost all dependencies by the modules of parse_tree.m on the modules
of hlds.m. The only such dependencies remaining now are on type_util.m.

compiler/hlds_data.m:
compiler/prog_data.m:
	Move the cons_id type from hlds_data to prog_data, since several parts
	of the parse tree data structure depend on it (particularly insts).
	Remove the need to import HLDS modules in prog_data.m by making the
	cons_ids that refer to procedure ids refer to them via a new type
	that contains shrouded pred_ids and proc_ids. Since pred_ids and
	proc_ids are abstract types in hlds_data, add predicates to hlds_data
	to shroud and unshroud them.

	Also move some other types, e.g. mode_id and class_id, from hlds_data
	to prog_data.

compiler/hlds_data.m:
compiler/prog_util.m:
	Move predicates for manipulating cons_ids from hlds_data to prog_util.

compiler/inst.m:
compiler/prog_data.m:
	Move the contents of inst.m to prog_data.m, since that is where it
	belongs, and since doing so eliminates a circular dependency.
	The separation doesn't serve any purpose any more, since we don't
	need to import hlds_data.m anymore to get access to the cons_id type.

compiler/mode_util.m:
compiler/prog_mode.m:
compiler/parse_tree.m:
	Move the predicates in mode_util that don't depend on the HLDS to a new
	module prog_mode, which is part of parse_tree.m.

compiler/notes/compiler_design.m:
	Mention prog_mode.m, and delete the mention of inst.m.

compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Move the predicates that depend on HLDS out of mercury_to_mercury.m
	to hlds_out.m. Export from mercury_to_mercury.m the predicates needed
	by the moved predicates.

compiler/hlds_out.m:
compiler/prog_out.m:
	Move predicates for printing parts of the parse tree out of hlds_out.m
	to prog_out.m, since mercury_to_mercury.m needs to use them.

compiler/purity.m:
compiler/prog_out.m:
	Move predicates for printing purities from purity.m, which is part
	of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use
	them.

compiler/passes_aux.m:
compiler/prog_out.m:
	Move some utility predicates (e.g. for printing progress messages) from
	passes_aux.m to prog_out.m, since some predicates in submodules of
	parse_tree.m need to use them.

compiler/foreign.m:
compiler/prog_data.m:
	Move some types from foreign.m to prog_data.m to allow the elimination
	of some dependencies on foreign.m from submodules of parse_tree.m.

compiler/*.m:
	Conform to the changes above, mostly by updating lists of imported
	modules and module qualifications. In some cases, also do some local
	cleanups such as converting predicate declarations to predmode syntax
	and fixing white space.
2004-06-14 04:17:03 +00:00
Zoltan Somogyi
7bf0cd03af Reduce the overhead of all forms of tabling by eliminating in many cases
Estimated hours taken: 32
Branches: main

Reduce the overhead of all forms of tabling by eliminating in many cases
the overhead of transferring data across the C/Mercury boundary. These
involve lots of control transfers as well as assignments to and from
Mercury abstract machine registers, which are not real machine registers
on x86 machines. Benchmarking in Uppsala revealed this overhead to be
a real problem.

The way we do that is by changing the tabling transformation so that instead
of generating sequences of calls to predicates from library/table_builtin.m,
we generate sequences of calls to C macros from runtime/mercury_tabling_pred.h,
and emit the resulting code string as the body of a foreign_proc goal.
(The old transformation is still available via a new option,
--no-tabling-via-extra-args.)

Since the number of inputs and outputs of the resulting C code sequences
are not always fixed (they can depend on the number of input or output
arguments of predicate being transformed), implementing this required
adding to foreign_procs a new field that allows the specification of extra
arguments to be passed to and from the given foreign code fragment. For now,
this mechanism is implemented only by the C backends, since it is needed
only by the C backends. (We don't support yet tabling on other backends.)

To simplify the new implementation of the field on foreign_procs, consolidate
three existing fields into one. Each of these fields was a list with one
element per argument, so turning them into a single list with a combined record
per argument should also improve reliability, since it reduces the likelyhood
of updates leaving the data structure inconsistent.

The goal paths of components of a tabled predicate depend on whether
-no-tabling-via-extra-args was specified. To enable the expected outputs
of the debugger test cases testing tabling, we add a new mdb command,
goal_paths, that controls whether goal paths are printed by the debugger
at events, and turn off the printing of events in the relevant test cases.

Also, prepare for a future change to optimize the trie structure for
user-defined types by handling type_infos (and once we support them,
typeclass_infos) specially.

compiler/table_gen.m:
	Change the tabling transformation along the lines described above.

	To allow us to factor out as much of the new code as possible,
	we change the meaning of the call_table_tip variable for minimal
	model subgoals: instead of the trie node at the end of the answer
	table, it is not now the subgoal reachable from it. This change
	has no effect as yet, because we use call_table_tip variables
	only to perform resets across retries in the debugger, and we
	don't do retries across calls to minimal model tabled predicates.

	Put predicates into logical groups.

library/table_builtin.m:
runtime/mercury_tabling_preds.h:
	When the new transformations in table_gen.m generate foreign_procs
	with variable numbers of arguments, the interfaces of those
	foreign_procs often do not match the interfaces of the existing
	library predicates at their core: they frequently have one more
	or one fewer argument. To prevent any possible confusion, in such
	cases we add a new variant of the predicate. These predicates
	have the suffix _shortcut in their name. Their implementations
	are dummy macros that do nothing; they serve merely as placeholders
	before or after which the macros that actually do the work are
	inserted.

	Move the definitions of the lookup, save and restore predicates
	into mercury_tabling_preds.h. Make the naming scheme of their
	arguments more regular.

runtime/mercury_minimal_model.c:
runtime/mercury_tabling_preds.h:
	Move the definition of a predicate from mercury_minimal_model.c
	to mercury_tabling_preds.h, since the compiler now needs to be
	able to generate an inlined version of it.

compiler/hlds_goal.m:
	Replace the three existing fields describing the arguments of
	foreign_procs with one, and add a new field describing the extra
	arguments that may be inserted by table_gen.m.

	Add utility predicates for processing the arguments of foreign_procs.

	Change the order of some existing groups of declarations make it
	more logical.

compiler/hlds_pred.m:
runtime/mercury_stack_layout.h:
	Extend the data structures recording the structure of tabling tries
	to allow the representation of trie steps for type_infos and
	typeclass_infos.

runtime/mercury_tabling_macros.c:
	Fix a bug regarding the tabling of typeclass_infos, which is now
	required for a clean compile.

compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
	Modify the generation of code for foreign_procs to handle extra
	arguments, and to conform to the new data structures for foreign_proc
	arguments.

compiler/llds.m:
	The tabling transformations can now generate significantly sized
	foreign_procs bodies, which the LLDS code generator translates to
	pragma_c instructions. Duplicating these by jump optimization
	may lose more by worsening locality than it gains in avoiding jumps,
	so we add an extra field to pragma_c instructions that tells jumpopt
	not to duplicate code sequences containing such pragma_cs.

compiler/jumpopt.m:
	Respect the new flag on pragma_cs.

compiler/goal_util.m:
	Add a predicate to create foreign_procs with specified contents,
	modelled on the existing predicate to create calls.

	Change the order of the arguments of that existing predicate
	to make it more logical.

compiler/polymorphism.m:
	Conform to the new definition of foreign_procs. Try to simplify
	the mechanism for generating the type_info and typeclass_info
	arguments of foreign_proc goals, but it is not clear that this
	code is even ever executed.

compiler/aditi_builtin_ops.m:
compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/dnf.m:
compiler/dupelim.m:
compiler/equiv_type_hlds.m:
compiler/exprn_aux.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/frameopt.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/higher_order.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/ite_gen.m:
compiler/layout_out.m:
compiler/livemap.m:
compiler/liveness.m:
compiler/llds_out.m:
compiler/loop_inv.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mark_static_terms.m:
compiler/middle_rec.m:
compiler/modes.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/pd_cost.m:
compiler/prog_rep.m:
compiler/purity.m:
compiler/quantification.m:
compiler/reassign.m:
compiler/rl_exprn.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeed_code.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Conform to the new definition of foreign_procs, pragma_cs and/or
	table trie steps, or to changed argument orders.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/lco.m:
compiler/module_util.m:
compiler/opt_util.m:
compiler/stack_opt.m:
compiler/trans_opt.m:
	Conform to the new definition of foreign_procs.

	Bring these modules up to date with our current code style guidelines,
	using predmode declarations, state variable syntax and unification
	expressions as appropriate.

compiler/mercury_compile.m:
	Conform to the changed argument order of a predicate in trans_opt.m.

compiler/options.m:
	Add the --no-tabling-via-extra-args option, but leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
	Document --no-tabling-via-extra-args option, though leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
doc/mdb_categories:
	Document the new goal_paths mdb command.

trace/mercury_trace_internals.c:
	Implement the new goal_paths mdb command.

tests/debugger/completion.exp:
	Conform to the presence of the goal_paths mdb command.

tests/debugger/mdb_command_test.inp:
	Test the existence of documentation for the goal_paths mdb command.

tests/debugger/print_table.{inp,exp*}:
tests/debugger/retry.{inp,exp*}:
	Use the goal_paths command to avoid having the expected output
	depend on the presence or absence of --tabling-via-extra-args.

tests/tabling/table_foreign_output.{m,exp}:
	Add a new test case to test the save/restore of arguments of foreign
	types.

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

tests/tabling/test_tabling:
	Make this script more robust.

	Add an option for testing only the standard model forms of tabling.
2004-06-07 09:07:23 +00:00
Zoltan Somogyi
679bfe629b Extend foreign_type declarations with optional annotations that allow the
Estimated hours taken: 4
Branches: main

Extend foreign_type declarations with optional annotations that allow the
programmer to assert that values of the given type can be passed to and from
Mercury without boxing, via casts, which are faster.

doc/reference_manual.texi:
	Document the new assertions.

compiler/prog_io_pragma.m:
	Parse the new assertions in foreign_type declarations.

compiler/prog_data.m:
compiler/hlds_data.m:
	Extend the foreign_type item and the foreign_type kind of HLDS type
	definition with a field containing a list of assertions. Currently
	the only assertion available is the one described above.

compiler/llds.m:
	Extend the structures containing the input/output arguments of
	foreign_procs with the list of applicable assertions.

compiler/make_hlds.m:
	Transfer any assertions from foreign_type items to the HLDS type
	definition.

compiler/pragma_c_gen.m:
	Transfer any assertions from the HLDS type definition to the
	descriptions of the inputs and outputs.

compiler/llds_out.m:
	If the new assertion is present in the input/output arguments of
	foreign_procs, generate casts instead of boxing/unboxing code.

compiler/foreign.m:
compiler/intermod.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_gen.m:
compiler/mlds.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Minor changes to conform to the changes in data structures.

tests/hard_coded/foreign_type_assertion.{m,exp}
	New test case to test the handling of the new assertion.

tests/hard_coded/Mmakefile:
	Enable the new assertion in C grades.
2004-05-12 14:24:35 +00:00
Zoltan Somogyi
4d9f8b8250 Fix a bug introduced by Simon's changes to equivalence types, which prevented
Estimated hours taken: 6
Branches: main

Fix a bug introduced by Simon's changes to equivalence types, which prevented
the browser for compiling when the library was compiled without intermodule
optimization. The symptom was a link error caused by the unify and compare
predicates for io__stream being local to io.c. This is a problem because
even though io__stream is primate to io.m, the browser generates references
to its unify and compare predicates, because io__stream is on the right hand
side of private type equivalences for io__input_stream and io__output_stream,
which are exported by io.m, and we now expand those equivalences.

compiler/hlds_data.m:
	Add an extra field to type constructors' definitions, saying whether
	the type constructor occurs on the right hand side of an equivalence.

	Make the orders of some predicate declarations and definitions
	consistent.

compiler/make_hlds.m:
	Fill in this field with a placeholder value.

compiler/equiv_type_hlds.m:
	Set this field to true if it is appropriate.

compiler/type_ctor_info.m:
	Fill in this field for builtin types (for which its value is moot,
	since such types are always exported).

compiler/hlds_pred.m:
	Change the definition of procedure_is_exported to say that a procedure
	is exported if it is a declared mode (not a mode created on demand in
	the calling module) of a unify or compare predicate of a type
	constructor in which this flag is set. This required changing the
	interface of procedure_is_exported to include a module_info.

compiler/export.m:
compiler/ml_code_gen.m:
compiler/rtti.m:
	Pass the extra argument to procedure_is_exported.

tests/hard_coded/abstract_eqv.{m,exp}:
tests/hard_coded/abstract_eqv_1.m:
	A new test case to check for the bug fixed by this change.

tests/hard_coded/Mmakefile:
	Enable the new test case.
2004-03-24 00:39:36 +00:00
Zoltan Somogyi
5d6fd3bd6f Reduce the dependence of earlier parts of the compiler on the later ones.
Estimated hours taken: 4
Branches: main

Reduce the dependence of earlier parts of the compiler on the later ones.
Unnecessary import_module declarations in top level modules such as hlds.m
cause unnecessary recompilations when adding new types in later modules,
such as submodules of ll_backend.m. This change reduces the number of such
unnecessary imports.

There are no changes in algorithms, only functionality being moved around.

compiler/code_model.m:
	Change this module from being a submodule of backend_libs.m to being a
	submodule of hlds.m, since nothing in it is dependent on any backend.

compiler/arg_info.m:
compiler/code_util.m:
	Change arg_info.m from being a submodule of ll_backend.m to being a
	submodule of hlds.m, since most of it is applicable to all current
	and foreseeable backends. Move the one exported predicate that is
	ll_backend dependent, and its support predicates, to code_util.m.

compiler/backend_libs.m:
compiler/ll_backend.m:
compiler/hlds.m:
	Update include_module declarations in accordance with the above.

compiler/prog_data.m:
compiler/term_util.m:
	Instead of defining two separate types for holding argument size and
	termination information, one including HLDS-specific information (in
	term_util.m) and one not (in prog_data.m), use a polymorphic type
	defined in prog_data.m and two monomorphic instances.

compiler/termination.m:
compiler/mercury_to_mercury.m:
	Change the predicates for writing out argument size and termination
	information to handle the polymorphic type (we don't need special
	handling of the monomorphic versions), and move them from termination.m
	to mercury_to_mercury.m, since this allows us to avoid some
	undesirable dependencies.

compiler/base_typeclass_info.m:
compiler/hlds_code_util.m:
	Move the predicate make_instance_string from base_typeclass_info.m
	to hlds_code_util.m, again because it allows us to remove some
	undesirable dependencies.

compiler/top_level.m:
compiler/backend_libs.m:
compiler/check_hlds.m:
compiler/hlds.m:
compiler/ll_backend.m:
compiler/parse_tree.m:
compiler/transform_hlds.m:
	Delete some import_module declarations of other top level modules
	in these top level modules. Some imports were totally unnecessary.
	Some imports were useful in only a small minority of submodules;
	those submodules now import the necessary top level modules directly.

	Move remaining import_module declarations to the implementation section
	where this is feasible.

	Where we still need to import modules we ideally shouldn't, note why.

compiler/*.m:
	Update imports of code_util and arg_info.

	In some cases, import top level modules no longer imported by the
	parent module.

	In some cases, delete unnecessary imports.
2004-03-23 10:52:14 +00:00
Zoltan Somogyi
c91313b32f Bring these modules up to date with our current coding style.
Estimated hours taken: 8
Branches: main

compiler/modules.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/bytecode_data.m:
compiler/prog_io_util.m:
	Bring these modules up to date with our current coding style. Use
	predmode declarations and state variable syntax where appropriate.
	Fix inconsistent indentation. Print more error messages using
	error_util.m for printing error messages.

compiler/trace_param.m:
	Add a new predicate for use by the updated code in handle_options.m.

compiler/error_util.m:
compiler/hlds_error_util.m:
	Make error_util.m to be a submodule of parse_tree.m, not hlds.m.
	Most of its predicates are not dependent on HLDS data structures.
	Move the ones that are into a new module, hlds_error_util, that
	is a submodule of hlds.m. Overall, this reduces the dependence
	of submodules of parse_tree.m, including modules.m, on submodules
	of hlds.m.

compiler/notes/compiler_design.html:
	Update the documentation of compiler modes to account for
	hlds_error_util.m.

compiler/hlds.m:
compiler/parse_tree.m:
	Update the list of included submodules.

compiler/*.m:
	Update module imports and module qualifications as needed for the
	change above.

tests/invalid/*.{exp,exp2}:
	Update the expected outputs of a bunch of test cases to reflect the new
	format of some warning messages due to the user error_util; they now
	observe line length limits, and print contexts in some cases where they
	were previously missing.
2004-03-19 10:19:53 +00:00
Zoltan Somogyi
c5610b6a8f Bring the modules in the language-independent part of the MLDS backend
Estimated hours taken: 8
Branches: main

compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_simplify_switch.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
	Bring the modules in the language-independent part of the MLDS backend
	up to date with our current coding standards.

	Use predmode declarations where appropriate.

	Use state variable syntax where appropriate. Reorder arguments where
	required to make this possible. For predicates that only read the
	ml_gen_info and aren't likely to write it in the future, delete the
	output ml_gen_info argument.

	Change large lambda expressions into named predicates where this
	improves readability, and in one case factor out duplicated code
	in lambda expressions.

	Standardize indentation. Shorten some variable names (e.g. by removing
	MLDS prefixes) where the new names are unambiguous, to make some goals
	fit on fewer lines.
2004-02-20 02:39:58 +00:00
Zoltan Somogyi
fa9ca36d03 This diff makes several files easier to read and to maintain (as well as
Estimated hours taken: 5
Branches: main

This diff makes several files easier to read and to maintain (as well as
more than 400 lines shorter), but contains no changes in algorithms whatsoever.

compiler/deep_profiling.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/post_typecheck.m:
compiler/prog_data.m:
compiler/purity.m:
compiler/type_util.m:
	Bring these modules into line with our current coding standards.

	Use predmode declarations 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 predicates with functions where appropriate.

	Standardize indentation.

compiler/*.m:
	Conform to the changes above.
2003-12-21 05:04:38 +00:00
Peter Ross
d40b70fec3 Fix a bug where the compiler was treating pseudo_imported external
Estimated hours taken: 6
Branches: main

Fix a bug where the compiler was treating pseudo_imported external
definitions incorrectly.

compiler/hlds_pred.m:
	Change the defintion of external in import_status so that it
	records the original import status, not just whether it is
	exported or not.

compiler/ml_code_gen.m:
	Don't generate any mlds representation for special predicates
	whose definition is external and pseudo_imported.

compiler/assertion.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/intermod.m:
	Adapt to the changes of the definition of status.

tests/hard_coded/Mmakefile:
tests/hard_coded/external_unification_pred.exp:
tests/hard_coded/external_unification_pred.m:
	Test case.
2003-12-03 16:12:10 +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
David Overton
2ad2f0a28e Allow types to be declared as "solver" types using the syntax
Estimated hours taken: 120
Branches: main

Allow types to be declared as "solver" types using the syntax
`:- solver type ...'.

For a non-solver type t (i.e. any type declared without using the
`solver' keyword), the inst `any' should be considered to be equivalent
to a bound inst i where i contains all the functors of the type t and
each argument has inst `any'.  For solver types, `any' retains its
previous meaning.

This is required to allow us to represent HAL's `old' inst using `any'.
In HAL, `old' is like `any' if the type is an instance of a particular
type class (`solver/1').  However, for types that are not instances of
`solver/1', `old' needs to be treated as though it is `bound'.

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

compiler/prog_data.m:
	Add a field to the type `type_defn' to record whether or not the
	type is a solver type.

compiler/hlds_data.m:
	Add an equivalent field to the type `hlds_type_body'.

compiler/prog_io.m:
compiler/make_hlds.m:
compiler/modules.m:
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Handle the new ":- solver type ..." syntax.

compiler/det_report.m:
compiler/equiv_type.m:
compiler/foreign.m:
compiler/hlds_code_util.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/module_qual.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/special_pred.m:
compiler/stack_opt.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
	Handle the changes to `type_defn' and `hlds_type_body'.

compiler/type_util.m:
	Add predicates `type_util__is_solver_type' and
	`type_body_is_solver_type'.

compiler/inst_match.m:
compiler/inst_util.m:
	In inst_matches_{initial,final,binding} and
	abstractly_unify_inst_functor, when we are comparing `any' insts, check
	whether or not the type is a solver type and treat it appropriately.

compiler/instmap.m:
compiler/modecheck_unify.m:
	Pass type information to abstractly_unify_inst_functor.

compiler/mode_util.m:
	Add a predicate `constructors_to_bound_any_insts' which is the same as
	`constructors_to_bound_insts' except that it makes the arguments of the
	bound inst `any' instead of `ground'.

tests/invalid/any_mode.m:
tests/invalid/any_mode.err_exp:
tests/hard_coded/any_free_unify.m:
	Modify these test cases to use a "solver" type instead of `int'.

tests/valid/any_matches_bound.m:
tests/valid/Mmakefile:
tests/invalid/Mmakefile:
tests/invalid/any_should_not_match_bound.m:
tests/invalid/any_should_not_match_bound.err_exp:
	Add new test cases.

extras/trailed_update/var.m:
clpr/cfloat.m:
	Modify to use the new `:- solver type' syntax.
2003-07-25 02:27:37 +00:00
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
Simon Taylor
82a950c0d9 Make Aditi work with `--highlevel-code'.
Estimated hours taken: 80
Branches: main

Make Aditi work with `--highlevel-code'.

(Note that this doesn't work with the current CVS version
of Aditi. The Aditi developers have rewritten the Aditi client
API, and haven't maintained the old version of the API, so Mercury
queries don't work at the moment. extras/aditi will be updated to
use the new interface as a separate change.)

extras/aditi/aditi_private_builtin.m:
extras/aditi/aditi.m:
	Move code to implement Aditi calls and updates into
	a aditi_private_builtin.m. These operations are now
	implemented using ordinary Mercury foreign procedures,
	rather than hand-coded C modules.

compiler/magic.m:
	Use calls to ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m to implement the
	procedures which interface between top-down Mercury
	code and Aditi procedures.

compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/mercury_compile.m:
compiler/notes/compiler_design.html:
	Add a pass to convert Aditi builtins (calls and updates)
	into ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m.

compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Add a new generic_call type -- `unsafe_cast'.
	aditi_builtin_ops.m needs to be able to cast
	closures from one type and inst to another.

	Delete the `aditi_call' alternative for `aditi_builtin',
	which is not needed after the change to magic.m described
	above.

	Add predicates `construct_tuple' and `deconstruct_tuple'.

compiler/*hlds.*.m:
compiler/call_gen.m:
compiler/ml_call_gen.m:
	Handle unsafe cast goals.

compiler/common.m:
compiler/higher_order.m:
compiler/unify_proc.m:
	Generate unsafe_cast goals instead of calls to
	private_builtin.unsafe_type_cast.

compiler/purity.m:
compiler/notes/compiler_design.html:
	Convert calls to private_builtin.unsafe_type_cast into
	unsafe_cast goals.

compiler/ml_code_gen.m:
	Don't attempt to generate code for Aditi procedures.

	Remove special case handling of calls to
	private_builtin.unsafe_type_cast -- such
	calls are now transformed away.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/maybe_mlds_to_gcc.m:
	Add the RL code to the generated C file.

compiler/llds_out.m:
compiler/c_util.m:
compiler/compile_target_code.m:
	Move code to generate a `.rlo' file and work out the
	name of the RL constant embeeded in the C file for
	a module into c_util.m, for use by the MLDS backend.

compiler/modules.m:
	Automatically import aditi_private_builtin when compiling
	with `--aditi'.

	We generate a C constant for the RL code for each module,
	so modules compiled with `--aditi' need to be treated
	by the build system as if they contain foreign code.

compiler/polymorphism.m:
	Tuple insertion and deletion no longer need special treatment.

compiler/llds.m:
compiler/ll_backend.*.m:
	Delete the Aditi alternatives of the `code_addr' type.

compiler/mode_util.m:
	Add function versions of in_mode, out_mode, etc.

compiler/prog_util.m:
	Add aditi_public_builtin_module (returns `aditi') and
	aditi_private_builtin_module (returns `aditi_private_builtin').

tests/valid/aditi_private_builtin.m:
tests/invalid/aditi_private_builtin.m:
tests/valid/Mercury.options:
tests/invalid/Mercury.options:
	Add a cut down version of extras/aditi/aditi_private_builtin.m
	for use in running the tests.
2003-03-18 02:43:52 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00