Commit Graph

163 Commits

Author SHA1 Message Date
Zoltan Somogyi
649b6908c3 Rename branch_delay_slot to have_delay_slot.
Estimated hours taken: 8

options.m:
	Rename branch_delay_slot to have_delay_slot.
	Set optimize_delay_slot in -O2 only if have_delay_slot was set earlier.
	This is possible now because the default optimization level is now
	set in mc.

mercury_compile:
	Change verbose output a bit to be more consistent.

dead_proc_elim:
	Export the predicates that will eventually be needed by inlining.m.

inlining.m:
	Use the information about the number of times each procedure is called
	to inline local nonrecursive procedures that are called exactly once.
	EXCEPT that this is turned off at the moment, since the inlining of
	parse_dcg_goal_2 in prog_io, which this change enables, causes the
	compiler to emit incorrect code.

prog_io:
	Moved the data type definitions to prog_data. (Even though prog_io.m
	is ten times the size of prog_data.m, the sizes of the .c files are
	not too dissimilar.)
1996-04-24 01:00:23 +00:00
Zoltan Somogyi
d344165793 Add a new option, --branch-delay-slot, intended for use by mc on
Estimated hours taken: 3

options:
	Add a new option, --branch-delay-slot, intended for use by mc on
	the basis of the configuattion script. It says whether the machine
	architecture has delays slots on branches.

	The setting of option should affect whether we set
	--optimize-delay-slots at -O2, but this doesn't work yet.

hlds_goal:
	Add an extra field to hold follow_vars infromation to disjunctions,
	switches and if-then-elses. I intend to use this information to
	generate better code.

*.m:
	Changes to accommodate the extra field.
1996-04-20 08:37:36 +00:00
Fergus Henderson
08633db05b Fix a bug in inlining of polymorphic predicates, which showed up
Estimated hours taken: 0.1

Fix a bug in inlining of polymorphic predicates, which showed up
for the `pseudoknot' benchmark when excess_assign was turned on again.

compiler/inlining.m:
	Make sure we substitute in the new values of any type
	parameters which are bound by an inlined call.
	This fixed a bug which led to the the code generator
	aborting because the code output from inlining.m was
	not type-correct.
	Also, tidy up the source code a bit and a some comments.

type_util.m:
	Add predicate type_list_subsumes/3, for use by inlining.m and
	modes.m.

modes.m:
	Use type_list_subsumes/3.
1996-04-12 23:30:54 +00:00
Fergus Henderson
a8c53337ea Implement overload resolution for predicates with the same name
Estimated hours taken: 4

compiler/{typecheck.m, modes.m}:
	Implement overload resolution for predicates with the same name
	and arity that occur in different modules.

	Amough other things, this change makes it practical to define
	pred '<'(int, int) in int.m and pred '<'(float, float) in float.m,
	without having to module-qualify uses of `<'.
1996-04-07 14:20:51 +00:00
Fergus Henderson
6a338a4ce8 A bunch of cleanups: improve error messages, tidy up the code.
Estimated hours taken: 3

A bunch of cleanups: improve error messages, tidy up the code.
Also, do some work towards supporting higher-order functions.

type_util.m:
	Add new predicate type_is_higher_order/3 for checking
	whether a type is a higher-order type.  This recognizes
	both higher-order predicate types and also higher-order
	function types.

code_info.m, modes.m, polymorphism.m, shapes.m:
	Use type_is_higher_order/3.

make_hlds.m:
	Fix another error message to do the right thing when
	reporting errors for functions.

mercury_to_mercury:
	List `func' in the table of operators, so that it gets
	parenthesized correctly.

modes.m, mode_errors.m:
	Improve the error message for attempted higher-order unifications:
	spit out some context, and if verbose_errors is enabled, spit
	out a long description.
1996-04-05 18:19:17 +00:00
Fergus Henderson
16bb3c050a Change the progress messages and error messages to print out
Estimated hours taken: 0.5

make_hlds.m, typecheck.m, modes.m, unique_modes.m, hlds_out.m:
	Change the progress messages and error messages to print out
	"function `mod:foo/2'" instead of the old message "pred
	mod:foo/3" (make_hlds.m) or "predicate foo/3" (typecheck.m,
	modes.m, unique_modes.m).
1996-04-03 11:52:34 +00:00
Zoltan Somogyi
2833bfffb7 Divided the old hlds.m into four files:
Estimated hours taken: 10

hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
	Divided the old hlds.m into four files:

	hlds_module.m defines the data structures that deal with issues
	that are wider than a single predicate. These data structures are
	the module_info structure, dependency_info, the predicate table
	and the shape table.

	hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.

	hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
	other parts of goal structures.

	hlsd_data.m defines the HLDS types that deal with issues related
	to data and its representation: function symbols, types, insts, modes.
	It also defines the types related to determinism.

	hlds.m is now an empty module. I have not removed it from CVS
	because we may need the name hlds.m again, and CVS does not like
	the reuse of a name once removed.

other modules:
	Import the necessary part of hlds.

det_analysis:
	Define a type that was up to now improperly defined in hlds.m.

prog_io:
	Move the definition of type determinism to hlds_data. This decision
	may need to be revisited when prog_io is broken up.

dnf, lambda:
	Simplify the task of defining predicates.

llds:
	Fix some comments.

mercury_compile:
	If the option -d all is given, dump all HLDS stages.

shape, unused_args:
	Fix formatting.
1996-04-02 12:12:24 +00:00
Fergus Henderson
456c0c2fc6 Fix a bug in the implementation of functions: the check for
Estimated hours taken: 1

compiler/modes.m:
	Fix a bug in the implementation of functions: the check for
	type subsumption (used as part of the process of figuring out
	if something is a function or a data constructor) was buggy.
1996-04-02 05:58:31 +00:00
Fergus Henderson
07974d0549 Fix misleading context on the error message for a call which
Estimated hours taken: 0.25

compiler/modes.m:
	Fix misleading context on the error message for a call which
	doesn't match any of the modes of a predicate.
	It used to say "in argument N", but the error message relates
	to all the arguments, not just the last one.
1996-03-26 13:36:17 +00:00
Fergus Henderson
3b36da6e77 Implement functional syntax. You can now use `:- func' in a similar manner
Estimated hours taken: 12

Implement functional syntax.  You can now use `:- func' in a similar manner
to `:- pred'.  For example, `:- func foo(int, int) = int.' declares a function,
and `:- mode foo(in, in) = out.' defines a mode for it.  You can write clauses
for functions, such as `foo(X, Y) = Z :- Z is 2*X + Y.'  Any term in the
head or body of a clause can be a function call, e.g. `bar(X, Y, foo(X, Y))'.

Until we have implemented a proper Mercury debugger, this syntax
should not be used (except that I might reimplement the functions
provided by Prolog's is/2 predicate using this syntax, rather than
the current special-case hack in the parser).

prog_io.m:
	Add syntax for declaring and defining functions.
	Disallow the use of `=' to define modes, as in `:- mode foo = bar.'
	(Instead, you should use `::'.  `==' is also allowed.)
	Also, use higher-order predicates to simplify some of the rather
	repetitious parsing code.

mercury_to_mercury.m, mercury_to_goedel.m, make_hlds.m, modules.m:
	Handle new functional syntax.

typecheck.m:
	Add support for functions, function types such as `func(int) = int',
	and currying.  (But there's currently no equivalent to call/N for
	functions, so function types and currying aren't very useful yet.)

undef_types.m:
	Add support for function types.

modes.m:
	Convert function calls into predicate calls.
	(This must be done after typechecking is complete,
	so I put it in mode analysis.)

hlds.m:
	Add new field `pred_or_func' to the pred_info.

hlds_out.m:
	Print out the `pred_or_func' field.

higher_order.m, unused_args.m, lambda.m, dnf.m:
	Pass extra pred_or_func argument to pred_info_init to specify that
	the thing being created is a predicate, not a function.

constraint.m, dependency_graph.m, hlds_out.m:
	`mercury_output_mode_subdecl' has been renamed
	`mercury_output_pred_mode_subdecl'.

prog_util.m:
	Add new predicate split_type_and_mode/3.

llds.m:
	Print out
		/* code for predicate '*'/3 in mode 0 */
	rather than
		/* code for predicate */3 in mode 0 */
	to avoid a syntax error in the generated C code.
1996-03-25 07:41:54 +00:00
Fergus Henderson
a7024afaf2 Fix misleading error message for taking the address of a predicate
Estimated hours taken: 0.25

compiler/modes.m:
	Fix misleading error message for taking the address of a predicate
	for which there were no mode declarations.
1996-03-11 14:24:59 +00:00
Fergus Henderson
bd2093d8b4 Fixes for two bugs in mode analysis, and
Estimated hours taken: 12

Fixes for two bugs in mode analysis, and
a first cut at support for `any' insts.
(The support for `any' is very preliminary,
has had only the most minimal of testing, and
doubtless has some bugs.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m undef_modes.m
unique_modes.m prog_io.m:
	Add new type of inst `any(uniqueness)' to prog_io.m, and
	change inst_match.m, mode_util.m, and other places to handle
	handle `any' insts.

inst_match.m:
	Fix bug in inst_merge: when merging `unique(f(ground)) and `unique',
	the result should be `ground', not `unique', since part of the
	data structure may be shared.  (This fix required adding several
	new predicates: `merge_uniq_bound' etc.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m polymorphism.m
prog_io.m switch_detection.m unique_modes.m:
	Fix a design bug: in a `bound' inst, the list of bound_insts
	must be sorted on the name+arity, not on the name+arg_insts.
	To achieve this, I changed the type of the first argument of
	functor/2 in the type bound_inst from `const' (just name) to
	`cons_id' (name+arity).
1996-03-09 16:04:29 +00:00
Fergus Henderson
e12bd14456 Fix a bug. In get_arg_insts, we need to pass down the functor
Estimated hours taken: 0.5

compiler/modes.m:
	Fix a bug.  In get_arg_insts, we need to pass down the functor
	arity as well as the functor name to get_arg_insts_2, since otherwise
	we have problems with functors of the same name but different arity.
1996-03-07 08:23:59 +00:00
Fergus Henderson
9d7bc6b6d9 A partial work-around for a problem with pragma c_code for implied modes.
Estimated hours taken: 0.5

A partial work-around for a problem with pragma c_code for implied modes.

compiler/modes.m:
	When mode-checking pragma_c_codes, make sure we record the proc_id
	that was selected.  (This may not be the same as the proc_id that
	the pragma_c_code was for, if it was an implied mode.)
1996-02-21 14:09:52 +00:00
Fergus Henderson
ed7f5f582d Reorder the code, in order to work around a SICStus Prolog code
Estimated hours taken: 2

compiler/modes.m:
	Reorder the code, in order to work around a SICStus Prolog code
	generation bug (!).
1996-02-07 10:12:26 +00:00
Fergus Henderson
6d7f4b9b30 Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5

Undo dylan's changes in the names of some library entities,
by applying the following sed script

	s/term_atom/term__atom/g
	s/term_string/term__string/g
	s/term_integer/term__integer/g
	s/term_float/term__float/g
	s/term_context/term__context/g
	s/term_functor/term__functor/g
	s/term_variable/term__variable/g
	s/_term__/_term_/g
	s/std_util__bool_/bool__/g

to all the `.m' and `.pp' files in the compiler and library directories.
The reason for undoing these changes was to minimize incompatibilities
with 0.4 (and besides, the changes were not a really good idea in the first
place).

I also moved `bool' to a separate module.
The main reason for that change is to ensure that the `__' prefix is
only used when it genuinely represents a module qualifier.
(That's what dylan's changes were trying to acheive, but `term__'
does genuinely represent a module qualifier.)

compiler/*.m:
	Apply sed script above;
	where appropriate, add `bool' to the list of imported modules.
1996-02-03 17:30:14 +00:00
Fergus Henderson
c66a0cd903 More changes to finally fix the compiler so that it handles
Estimated hours taken: 4

More changes to finally fix the compiler so that it handles
Simon Taylor's nasty test case correctly.

Change unique_modes.m to invoke modecheck_unify_procs in unify_procs.m,
in case unique_modes.m adds new unify_requests for unification predicates
with `mostly_unique' modes.

switch_detection.m, cse_detection.m, det_analysis, unique_modes:
	Export new predicates to process a single procedure at a time.

cse_detection.m:
	Rearrange things so that it only redoes mode checking and switch
	detection for the single procedure, not for a every mode of a predicate,
	by calling `modecheck_proc' and `detect_switches_in_proc'.

hlds.m:
	Add new field `can_process' to the proc_info.

modes.m, unique_modes.m:
	Don't modecheck a procedure if its can_process field = no.

unify_proc.m:
	Set the can_process field to `no' when adding unify procs after
	a call to unify_proc__request_unify, and then back to yes again
	when we are ready to process them in modecheck_unify_procs.
	Add a new parameter to modecheck_unify_procs which specifies
	whether we need to do ordinary mode checking or unique mode
	checking.  If we need to do unique mode checking, then after
	doing ordinary mode checking, invoke `detect_switches_in_proc',
	`cse_detect_in_proc', `determinism_check_proc', and
	`unique_modes__check_proc' on the procedure.

unique_modes.m:
	After checking ordinary predicates, invoke modecheck_unify_procs.
	Add very_verbose progress messages.
1996-01-22 05:07:39 +00:00
Fergus Henderson
837661243b This check-in combines several changes.
Estimated hours taken: 16

This check-in combines several changes.

* Change mercury_compile.pp so that it continues as far as possible
  after errors.

* Split the parts of mercury_compile.pp which handle module
  imports and exports into a new module called `modules.m'.

* Move the polymorphism.m pass after determinism analysis and unique mode
  checking.  This is because unique_modes.m may change the mode in which
  a unification predicate is called; as a result, we need to do mode
  checking, determinism analysis, and unique mode checking for new
  modes of unification predicates which are requested only after
  unique mode checking.  That won't work if we have done polymorphism.m
  in between mode checking and determinism analysis, since unification
  predicates are created without type_info arguments, and polymorphism.m
  cannot be run on just one predicate at a time.  (NB. I haven't changed
  unique_modes.m to actually do this yet.)
  I also had to move lambda.m after polymorphism.m, since polymorphism.m
  doesn't handle higher-order pred constants.

* Fix determinism analyis of simple_test unifications.
  The compiler would think that a unification of an inst such as
  `bound(foo)' with itself could fail.  The problem is that there is no
  `can_fail' field for simple_test unifications, so determinism.m just
  assumes that they can all fail.  I fixed this by changing modes.m to
  optimize away simple_tests that cannot fail.

* Fix determinism analyis of complicated_unifications.
  Again, determinism analysis just assumed that all complicated_unifications
  were semidet, because unify_proc.m always declared the out-of-line
  unification predicates to be semidet.  The fix was to pass the determinism
  inferred during mode analysis to unify_proc__request_unify.
  However, the '='(in, in) mode still needs to be semidet - its address is
  taken and put into the type_infos, and so it needs to have the
  right interface.  To handle det '='(in, in) unifications, the
  determinism also needs to be passed to unify_proc__search_mode_num,
  which will select the '='(in, in) mode only if the determinism is
  semidet.  (It would of course be better to optimize det '='(in, in)
  unifications to `true', but they are unlikely to occur much in real
  code anyway, so that is a low priority.)

* Compute the instmap deltas for all variables, not just the non-local
  variables of a goal, because variables which are not present in a goal
  can become nondet live if the goal is e.g. a nondet call.

mercury_compile.pp:
	- Rearrange the order of the passes as described above.
	- Add code to call check_undef_types and check_undef_modes
	  directly rather than via typecheck.m/modes.m.
	  Stop only if we get an undef error; if we get any other
	  sort of type/mode error, we can keep going.
	- Move lots of code to modules.m.

modules.m:
	New file, containing code moved from mercury_compile.pp.

polymorphism.m:
	Make sure that the goals that we generate have the correct
	determinism annotations.  Handle switches.
	Put back the call to lambda__transform_lambda.

lambda.m:
	Put back the stuff that allowed lambda.m to be called from
	polymorphism.m.

modes.m, unify_proc.m, call_gen.m, polymorphism.m,
	Pass the determinism of the unification to unify_proc__request_unify,
	so that it can declare the right determinism for the unification
	predicate.  (Previously it just assumed that all complicated
	unifications were `semidet'.)
	Also pass the determinism to unify_proc__search_mode_num, so that
	it will generate a new unification pred for deterministic '='(in,in)
	unifications rather than calling the existing semidet one.

modes.m, typecheck.m:
	Remove the calls to check_undefined_types and check_undefined_modes.
	They are now instead called directly from mercury_compile.pp.

modes.m:
	Don't call lambda__transform_lambda.
	Optimize away simple_tests that cannot fail.

modes.m, unique_modes.m:
	Call mode_info_get_instmap/2 rather than mode_info_get_vars_instmap/3.

mode_info.m:
	Delete the predicate mode_info_get_vars_instmap/3.
1996-01-22 00:55:15 +00:00
Fergus Henderson
729c0a941c Rearrange the ordering of the different phases in the compiler.
Estimated hours taken: 6

Rearrange the ordering of the different phases in the compiler.

Moved lambda elimination (lambda.m) after unique_modes.m,
because mode analysis must have been fully completed before lambda
elimination, so that we get the right mode on the introduced
predicates.  Also moved inlining.m and common.m after unique modes,
since they are optimization passes, not semantic checking passes.

The cse_detection.m, switch_detection.m, and determinism.m passes now
need to recursively traverse lambda goals.  (Previously they assumed
that lambda goals had already been eliminated.)

mercury_compile.pp:
	Move the inlining.m and common.m passes from semantic_phases
	to middle_phases.

polymorphism.m:
	Remove the code which called lambda.m.

switch_detection.m:
	Recursively traverse lambda goals.

cse_detection.m:
	Recursively traverse lambda goals.
	Also, when redoing mode analysis and switch detection,
	we shouldn't reinvoke lambda.m.

det_analysis.m, det_report.m:
	Recursively traverse lambda goals, check for determinism
	errors in them, and report them.
	Also, print the calling predicate name & mode in the error
	message for calls to predicates with cc_* determinism in
	all-solutions contexts.

modes.m:
	Add an extra argument to modecheck_unification that specifies
	how we should recursively process lambda goals, so that we
	can do the right thing when called from unique_modes.m.
	The right thing in this case is to call unique_modes__check_goal
	instead of modecheck_goal, and to then invoke lambda__transform_lambda
	on the result.

unique_modes.m:
	Make sure we don't clobber the predicate table, since we now
	indirectly call lambda__transform_lambda, which inserts new
	predicates into the table.
	Also, simplify the code a little and add a sanity check.

lambda.m:
	Make some changes that were needed because lambda.m now comes
	directly after (unique_)modes.m not after polymorphism.m.
1996-01-19 06:02:08 +00:00
Fergus Henderson
907b27299f Fix bug in mode analysis of lambda expressions which caused the
Estimated hours taken: 0.3

Fix bug in mode analysis of lambda expressions which caused the
compiler to report a spurious error for the following code
fragment:

>	io__tell("foo", Err),
>	{ require(lambda([] is semidet, Err = ok), "open failed") }

compiler/modes.m:
	After mode-checking the goal in a lambda expression, we must
	restore the initial instmap; although the lambda expression
	is guaranteed not to have bound any variables, it may have
	added changed the instmap by adding some information.
1996-01-14 15:48:14 +00:00
Fergus Henderson
ebe792f1d8 A large bunch of changes to improve unique mode checking.
Estimated hours taken: 18

---------------------------------------------------------
A large bunch of changes to improve unique mode checking.
---------------------------------------------------------

Unique mode checking is now quite similar to redoing mode checking,
except that as it goes along it changes the insts of variables which
may be used again on backtracking from `unique' to `mostly_unique',
and except that it doesn't do any rescheduling.

(This contrasts with my original very simple approach which just kept track
of which variables were nondet-live - that approach only works
for the top-level of the inst.  The new approach handles insts
such a list whose skeleton is unique and whose elements are mostly_unique.)

Another improvement is that we now also detect errors resulting from
shallow (semidet) backtracking in if-then-elses and negations, which
previously we missed.

Also, fix a bug in the handling of `X = f(_)' when X is unique:
it was inferring the delta instmap `X -> unique(f(ground))'
rather than `X -> unique(f(unique))'.

unique_modes.m:
	Major rewrite.

inst_match.m:
	Add new predicate `make_mostly_uniq_inst' which replaces
	every occurence of `unique' in an inst with `mostly_uniq'.
	Fix bug in abstractly_unify_inst_functor_3 which caused
	above-mentioned problem with `X = f(_)' when X is unique.

hlds.m, prog_io.m, mercury_to_mercury.m, mode_util.m, undef_modes.m:
	Add a new inst_name `mostly_unique(inst)'; the inst
	`defined_inst(mostly_unique(X))' is identical to the
	inst X with every occurrence of `unique' replaced with
	`mostly_unique'.  This change was required in order to
	implement the `make_mostly_uniq_inst' predicate for recursive
	insts.

mode_info.m:
	Add a new field holding the nondet-live variables,
	for use by unique_modes.m.

modes.m:
	Export a whole bunch of previously private predicates,
	for use by unique_modes.m.

det_analysis.m, det_report.m, make_hlds.m, mercury_compile.pp, prog_io.m,
value_number.m:
	Fix unique mode errors resulting from I/O operations (calls
	to io__lookup_bool_opt) in the conditions of if-then-elses.
1996-01-14 15:16:30 +00:00
Fergus Henderson
ce9c578a0e Fix some bugs with higher-order preds in data structures.
Estimated hours taken: 2

Fix some bugs with higher-order preds in data structures.

modes.m:
	Make sure we don't try to insert higher-order preds
	unifications into the unify_request queue.

polymorphism.m:
	Make sure that we handle higher-order unifications by
	calling builtin_unify_pred (which does a runtime error)
	rather than trying to find the non-existent unification
	predicate for the pred type.
1996-01-04 18:38:09 +00:00
Fergus Henderson
981f709108 Oops, the last bug fix didn't quite work.
Estimated hours taken: 0.5

compiler/modes.m:
	Oops, the last bug fix didn't quite work.
1995-12-30 21:03:22 +00:00
Fergus Henderson
3d9b65efb4 Fix bug in my last change - when constructing new goal_infos
Estimated hours taken: 0.5

compiler/modes.m:
	Fix bug in my last change - when constructing new goal_infos
	I had forgotten to fill in the delta_instmap.
1995-12-30 07:59:13 +00:00
Dylan Shuttleworth
3ab8d92226 Change names with badly placed double underscores (ie where the part of
Estimated hours taken: _2___

Change names with badly placed double underscores (ie where the part of
a name before a double underscore is not the same as the module name.)

Reflect changes in the library interface.

compiler/*:
	Use the newer, more correct form of the term and bool names.
	Predicates "bool__" are now "std_util__bool" and labels of
	the term ADT are now "term_" instead of "term__".

compiler/vn*.m:
	change all names "vn__*" to a correct module prefix.  All the
	names remain qualified.

compiler/hlds.m:
	s/\<is_builtin__/hlds__is_builtin_/g
	s/\<dependency_info__/hlds__dependency_info_/g

compiler/unify_proc.m:
	s/\<unify_proc_info__/unify_proc__info_/g

compiler/transform.m:
	s/\<reschedule__conj/transform__reschedule_conj/g
1995-12-29 03:45:20 +00:00
Fergus Henderson
f85be237a0 If the condition of an if-then-else cannot succeed,
Estimated hours taken: 2

compiler/modes.m:
	If the condition of an if-then-else cannot succeed,
	delete the unreachable `then' part.
1995-12-28 03:28:37 +00:00
Fergus Henderson
09e76e9e4c Two changes to make mode analysis handle erroneous goals.
Estimated hours taken: 4

Two changes to make mode analysis handle erroneous goals.

1. Fix a bug in mode analysis where it reported a "map__lookup failed" error
for `query(X) :- test(X), gen(X).' if gen/1 had determinism erroneous.
The reason it did this was that in this case mode analysis was failing
to wake up all of the pending goals before leaving the conjunction.
The fix was to wake up all the goals at once, rather than waking them
up one at a time.

delay_info.m:
	Replace the old exported predicate delay_info__wakeup_goal
	with a new predicate delay_info_wakeup_goals that returns
	a list of all the goals woken.

modes.m, transform.m:
	Call delay_info__wakeup_goals instead of delay_info__wakeup_goal.

2. Fix another potential bug in mode analysis - if the instmap becomes
unreachable, then we must make sure we wake up all delayed goals.

delay_info.m:
	Add new predicate delay_info__bind_all_vars.

mode_info.m:
	Change mode_info_set_instmap so that it will call
	delay_info__bind_all_vars if the instmap is `unreachable'.
1995-11-23 14:06:25 +00:00
Fergus Henderson
b41c79f9fa Fix bug in mode analysis with partially instantiated modes
Estimated hours taken: 4

Fix bug in mode analysis with partially instantiated modes
that caused the compiler to generate incorrect code.

compiler/{modes.m,mode_util.m}:
	`categorize_unify_var_functor' was computing the wrong
	`list(uni_mode)' in the `unify_info' for `construction'
	and `deconstruction' unifications.  The modes for the
	left-hand-side should have been the modes of the various
	fields of the variable on the LHS, assuming that the
	variable had the same functor as the functor on RHS.
	But instead they were all duplicates of the top-level
	mode of the LHS variable.  (It worked if the top-level
	mode was `in' or `out', since in that case the argument
	modes would all have been `in' or `out' respectively too.
	But it failed if the top-level mode was a partially
	instantiated mode.)   This caused `split_complicated_subunifies'
	to get very confused and ultimately caused the compiler
	to generate incorrect code.  I fixed this by changing
	modes.m so that it computed the correct information.
	This also required changing `mode_util__modes_to_uni_modes'
	so that it took a list of modes for the LHS rather than a
	single mode.
1995-11-15 01:22:39 +00:00
Fergus Henderson
623bb271d0 Improve documentation.
Estimated hours taken: 0.5

compiler/{modes.m,hlds.m}
	Improve documentation.
1995-11-01 13:46:17 +00:00
Zoltan Somogyi
3224e94532 A new pass to remove unnecessary assignment unifications.
excess:
	A new pass to remove unnecessary assignment unifications.

mercury_compile:
	Call the new excess assignment module.

options:
	Add a new option, excess_assign, to control the new optimization.
	Add another, num-real-regs, to specify how many of r1, r2 etc are
	actually real registers. The default is now set to 5 for kryten;
	later it should be supplied by the mc script, with a value determined
	at configuration time.

tag_switch:
	Use num-real-regs to figure out whether it is likely to be worthwhile
	to eliminate the common subexpression of taking the primary tag of
	a variable. Also fix an old performance bug: the test for when a
	jump table is worthwhile was reversed.

value_number, vn_block:
	Do value numbering on extended basic blocks, not basic blocks.

vn_debug:
	Modify an information message.

labelopt:
	Clean up an export an internal predicate for value numbering. Replace
	bintree_set with set.

middle_rec:
	Prepare for the generalization of middle recursion optimization
	to include predicates with an if-then-else structure.

cse_detection:
	Fix a bug: when hoisting a common desconstruction X = f(Yi), create
	new variables for the Yi. This avoids problems with any of the Yis
	appearing in other branches of the code.

goal_util:
	Add a new predicate for use by cse_detection.

common:
	Fix a bug: recompute instmap deltas, since they may be affected by the
	optimization of common structures.

code_info:
	Make an error message more explicit.

det_analysis:
	Restrict import list to the needed modules.

*.m:
	Import assoc_list.
1995-10-27 09:39:28 +00:00
Fergus Henderson
4b91fb61cf Add new predicate `inst_matches_binding'.
inst_match.m:
	Add new predicate `inst_matches_binding'.
	This is like `inst_matches_final', except that it ignores
	differences in uniqueness.

modes.m, det_report.m, constraint.m:
	Use `inst_matches_binding' rather than `inst_matches_final'
	when testing whether a goal has no output variables.
	This avoids some problems with unique modes.
1995-10-24 08:36:49 +00:00
David Jeffery
f75693e80a The C interface.
The changes made allow declarations of the form:

:- pragma(c_code, predname(Varname1::mode1, Varname2::mode2, ...),
	"Some C code to execute instead of a mercury clause;").

There are still a couple of minor problems to be fixed in the near future:
If there is a regular clause given as well as a pragma(c_code, ...) dec, it
is not handled well, and variables names '_' are not handled well.

prog_io.m:
	parse the pragma(c_code, ...) dec.
hlds.m:
	define a new hlds__goal_expr 'pragma_c_code'.
make_hlds.m:
	insert the pragma(c_code, ...) dec. as a pragma_c_code into the hlds.
det_analysis.m:
	infer that pragma_c_code goals are det.
modes.m:
	convince the mode checker that the correct pragma variables are bound
	etc.
quantification.m:
	quantify the variables in the pragma(c_code, ...) dec.
code_gen.pp:
	convert pragma_c_code into pragma_c (in the llds).
llds.m:
	define a new instr, pragma_c. Output the pragma_c
hlds_out.m:
mercury_to_mercury.m:
mercury_to_goedel.m:
	spit out pragma(c_code, ...) decs properly

*.m: 	handle the new pragma_c_code in the hlds or the new pragma_c in the llds
1995-10-17 11:13:13 +00:00
Fergus Henderson
2a1497bc31 A bunch of changes to fix another missing bit of unique modes.
Previously we didn't check if a unification was unifying with
a clobbered value.  With these changes, we now do.

inst_match.m:
	Add an extra parameter `unify_is_real' to `abstractly_unify_inst'.
	The extra parameter specifies whether this is a "real" or "fake"
	unification; if it is fake, unifications with clobbered values
	are allowed.

modes.m:
	Pass the above-mentioned new parameter to `abstractly_unify_inst'.

prog_io.m, hlds.m:
	Store the above-mentioned new parameter in the unify_inst table.

mode_util.m:
	Use the above-mentioned new parameter when looking up an inst
	in the unify_inst table.

undef_modes.m, mercury_to_mercury.m:
	More miscellaneous changes to handle new `unify_is_real' parameter.
1995-10-09 17:12:47 +00:00
Fergus Henderson
c42a89455e Fix unique mode errors detected by the compiler's stricter checking.
compiler/{mode_errors.m,mode_info.m,modes.m,typecheck.m}:
	Fix unique mode errors detected by the compiler's stricter checking.
1995-10-09 17:07:17 +00:00
Fergus Henderson
6f0e83f0ab Fix the bug that Zoltan reported in unique mode checking.
modes.m:
	Fix the bug that Zoltan reported in unique mode checking.
	We should now detect most (not yet all) cases of using
	`clobbered' insts.

	[NOTE: This change might potentially break things; check
	~fjh/log/test_mercury.out before doing a CVS update.]
1995-10-08 17:02:04 +00:00
Fergus Henderson
0d36b0889e Fix bug in the transformation of higher-order pred constants
modes.m:
	Fix bug in the transformation of higher-order pred constants
	into lambda goals: it was not calculating the non-local
	vars correctly.
1995-09-24 06:15:49 +00:00
Fergus Henderson
432eee8f1f Fix singleton variable warnings by deleting useless code.
code_exprn.m, modes.m:
	Fix singleton variable warnings by deleting useless code.

shapes.m, typecheck.m:
	Fix singleton variable warnings by renaming variables so that they
	start with an underscore.

make_hlds.m:
	Pass the context down into transform_goal_2, unravel_unification,
	insert_arg_unifications, and append_arg_unifications, so that
	the goal_info_context in the newly built HLDS is never empty.
	This is needed because the new warn_singletons uses the context,
	so it has to be valid.

unify_proc.m:
	Pass a term__context to unravel_unification (as required by
	above change).

quantification.m:
	Rearrange some comments that got shifted a dozen
	lines from the code they referred to.

vn_util.m:
	Fix omission in Zoltan's changes with `succip(FramePointer)'
	which caused "Software Error: unexpected lval in vn_...".
1995-09-06 17:29:28 +00:00
Fergus Henderson
ce9a5cf7d5 Optimize away unifications with dead variables.
modes.m:
	Optimize away unifications with dead variables.
	(The code generator already does that, but by
	that time we have already allocated unnecessary
	stack slots for them.)

code_exprn.m:
	Avoid generating sequences such as `r2 = r3; r3 = r2;'
	when a register already contains the correct value.
	(This change was in fact at least as much Tom's work as mine.)

store_alloc.m:
	For disjunctions, we only want to allocate registers
	for the variables that are output by the disjunction.
	The inputs should go in framevars, not in registers.
	This avoids much of the register-shuffling
	in the code generated for e.g. list__member(out, in).
	(This change was in fact at least as much Tom's work as mine.)
1995-09-06 11:42:11 +00:00
Fergus Henderson
f8dd293cd7 Finish implementing mode checking of lambda expressions.
modes.m, mode_errors.m, mode_util.m:
	Finish implementing mode checking of lambda expressions.

inst_match.m:
	Mode checking of higher-order pred modes was slightly
	too strict - relax it a little.

modes.m, mode_errors.m, mode_info.m:
	For mode errors that occur in predicate calls,
	record the argument number that they occurred in,
	and print it out in mode error messages.
	(This also fixes a bug where some of the determinism
	error messages would say "in argument 0 of call to pred ...").

polymorphism.m:
	A couple of minor simplifications.
1995-08-27 17:27:18 +00:00
Zoltan Somogyi
bebe96be34 Look inside blocks introduced by value numbering when looking
frameopt:
	Look inside blocks introduced by value numbering when looking
	restorations of succip.

value_number, opt_util:
	If we are using conservative garbage collection, disable value
	numbering for blocks that allocate more than one cell on the heap.
	This allows value numbering of most blocks to work in the absence
	of -DALL_INTERIOR_POINTERS.

all other source files:
	Clean up "blank" lines that nevertheless contain space or tab
	characters.
1995-08-27 11:10:20 +00:00
Fergus Henderson
b7e8cb0c96 Move the 800 lines of code for inst__merge,
modes.m, mode_util.m, inst_match.m:
	Move the 800 lines of code for inst__merge,
	abstractly_unify_inst, and the predicates they
	call from modes.m into inst_match.m.
	(modes.m was getting too huge.)
1995-08-27 08:18:08 +00:00
Fergus Henderson
760b99015c Another big batch of changes for higher-order predicates.
This set of changes includes most of the work necessary for
mode and determinism checking of higher-order predicates.

prog_io.m:
	Change the syntax for lambda expressions: they need
	to have a determinism declaration.  Lambda
	expressions must now look like this:

		lambda([X::in, Y::out] is det, ...goal...).
				       ^^^^^^

	Note that both the modes and the determinism are mandatory,
	not optional.

hlds.m:
	Insert a determinism field in the lambda_goal structure.

hlds_out.m, inlining.m, make_hlds.m, modes.m, polymorphism.m, quantification.m,
switch_detection.m, typecheck.m:
	Modified to use lambda_goal/4 rather than lambda_goal/3.

prog_io.m:
	Add a new field to the `ground' inst, of type `maybe(pred_inst_info)'.
	We use this to store the modes and determinism of higher-order
	predicate terms.

code_info.m, inst_match.m, mercury_to_mercury.m, mode_util.m, modes.m,
polymorphism.m, shapes.m, undef_modes.m:
	Modified to handle higher-order pred modes:
	use ground/2 rather than ground/1.
	(Note that modes.m still requires a bit more work on this.)

llds.m:
	Add a new field to the call_closure/3 instruction to hold the
	caller address for use with profiling, since the C macros
	require a caller address.

dup_elim.m, frame_opt.m, garbage_out.m, live_map.m, middle_rec.m, opt_debug.m,
opt_util.m, value_number.m, vn_*.m:
	Modified to use call_closure/4 rather than call_closure/3.

mercury_to_mercury.m:
	Export mercury_output_det for use by hlds_out.m.
1995-08-26 20:04:46 +00:00
Zoltan Somogyi
736a1c554d Applied Fergus's fix to allow repeated modechecking after his
modes.m:
	Applied Fergus's fix to allow repeated modechecking after his
	recent changes.

peephole:
	Be more aggressive in optimizing instruction sequences created
	by the replacement of tailcalls with the code from the start
	of the procedure.
1995-08-26 15:11:19 +00:00
Fergus Henderson
cdc666a331 More work on higher order predicates and lambda goals.
Lambda expressions now work, and you can now use polymorphic predicates
as higher-order pred terms.  (Mode checking and determinism checking
are still not implemented, and the modes of call/N are very restrictive.
But these change makes solutions/2 a lot more useful now.)

hlds.m:
	Comment out the stuff for recording num_warnings, since it
	wasn't being used.  Instead we now use that slot in the
	module_info for a counter which holds a number to use to
	name the predicates for lambda expressions.  Add a new
	predicate module_info_next_lambda_count/3 to get and
	increment this counter.

modes.m:
	Transform higher-order pred constants into lambda expressions.
	(Also, use slightly more meaningful variable names in a few places.)

polymorphism.m:
	Use module_info_next_lambda_count/3 to name the predicates
	created for lambda expressions.

code_util.m:
	Handle __LambdaGoal__ labels correctly.
1995-08-26 06:43:35 +00:00
Fergus Henderson
16d6bd3c05 More work on lambda expressions / higher-order predicates.
quantification.m:
	Fix ANOTHER bug in quantification of lambda expressions.

hlds_out.m:
	Fix minor indentation problem in output of lambda expressions.

polymorphism.m:
	When a lambda expression is encountered, convert it into a
	new predicate.  (Works OK, with one caveat: you can currently
	only have one lambda expression per program.)

make_hlds.m:
	Export a couple of predicates so that polymorphism.m can use
	them when it is creating new predicates for lambda expressions.

modes.m:
	Fix a problem with quantification of lambda goals.
	Add some code to convert higher order predicate calls into
	lambda expressions so that they get mode checked and
	polymorphism-processed properly.  (Unfinished, code
	commented out.)

hlds.m:
	Simplify the code for goal_info__remove_feature.
1995-08-24 18:37:54 +00:00
Fergus Henderson
160a32038a More work on lambda expressions.
hlds.m:
	Insert new `list(mode)' field in the lambda_goal/2 structure.

hlds_out.m, inlining.m, quantification.m, switch_detection.m,
	Use lambda_goal/3 instead of lambda_goal/2.

parser.m, make_hlds.m, typecheck.m, modes.m:
	Parse, typecheck, and modecheck lambda expressions.

mercury_to_mercury.m:
	Export mercury_output_mode/4 for use by hlds_out.m.
1995-08-20 18:17:36 +00:00
Fergus Henderson
50e1a35932 A few minor changes to comments here and there.
mercury/compiler/*:
	A few minor changes to comments here and there.
1995-08-18 19:14:49 +00:00
Zoltan Somogyi
8aee404355 When introducing new goals, give them a context, since it may be
modes:
	When introducing new goals, give them a context, since it may be
	needed for error messages in determinism analysis.

hlds_out:
	Print the context of each goal if -V is set.

det_analysis:
	Try to ensure that we don't print the names of introduced variables.
1995-08-03 07:14:54 +00:00
Fergus Henderson
b87de68334 Implement unique modes. We do not handle local aliasing yet, so this
-------------------------------------------------------

Implement unique modes.  We do not handle local aliasing yet, so this
is still not very useful, except for io__state.  Destructive update is
not yet implemented.  Also note that this really only implements
"mostly unique" variables that may be non-unique on backtracking - we
don't check that you don't backtrack over I/O, for example.

prog_io.m, mode_util.m, modes.m, inst_match.m:
	Major changes to Handle unique modes.

mercury_to_mercury.m, polymorphism.m, prog_out.m, undef_modes.m:
	Use `ground(Uniqueness)' rather than just `ground'.

compiler/*.m:
	Fix compile errors now that unique modes are enforced: add a
	few calls to copy/2, and comment out lots of unique mode
	declarations that caused problems.

typecheck.m, mode_info.m:
	Hack around the use of unique modes, which doesn't work
	because we don't allow local aliasing yet: make the insts
	`uniq_type_info' and `uniq_mode_info' not unique at all,
	and add a call to copy/2 when extracting the io_state from
	type_info or mode_info.

-------------------------------------------------------

Plus a couple of unrelated changes:

hlds.m:
	Change the modes for the special predicates from `ground -> ground'
	to `in', so that any error messages that show those modes
	come out looking nicer.

	Add a new shared_inst_table for shared versions of user-defined
	insts.

mercury_to_goedel.m:
	Use string__is_alnum_or_underscore.
1995-08-02 07:53:53 +00:00
Fergus Henderson
0bbf5def61 Fix obscure "map_lookup failed" bug triggered by a partially
modes.m, unify_proc.m:
	Fix obscure "map_lookup failed" bug triggered by a partially
	instantiated mode of a complicated unification predicate, whose
	procedure body contained a call the the same complicated
	unification predicate in a different partially instantiated
	mode.

constraint.m, cse_detection.m:
	Change calls to modecheck to match new simplified interface.
1995-08-01 13:16:45 +00:00