Commit Graph

77 Commits

Author SHA1 Message Date
Adrian Pellas-Rice
1c65d003f7 Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
Estimated hours taken: 4.5
Branches: main

Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.

compiler/hlds_goal.m
        Create a new type, the `shorthand_goal_expr', for goals kinds that
        are implemented by a (ordinary_hlds + shorthand) -> (ordinary_hlds)
        transformation.  At present, bi_implication is the only kind of
        of goal that is implemented in this way.

        Moved bi_implication functor from the type goal_expr to the new
        shorthand_goal_expr type.

        Added the functor shorthand to the goal_expr type.

compiler/*.m
        Change switches on hlds_goal_expr that call error when they recognise
        `bi_implication' from calling error when they recognise
        `bi_implication' to calling error when they recognise `shorthand'.

        For all predicates K that
                a) switch on hlds_goal_expr and
                b) perform non-trivial processing when they recognise
                   `bi_implication'
        change K such that it now calls K_shorthand upon recognising the
        functor `shorthand'. Define K_shorthand to switch on
        shorthand_goal_expr, where the code for the `bi_implication' case
        formerly contained in K is now contained in K_shorthand.
2001-04-07 14:05:03 +00:00
Tyson Dowd
711da78188 Rename foreign_code as foreign_proc where appropriate in the compiler.
Estimated hours taken: 4.0
Branches: main

Rename foreign_code as foreign_proc where appropriate in the compiler.
The rationale for this change is that it makes maintaining the code much
simpler because it is clear whether `foreign' refers to a slab of code
(foreign_code) or a procedure (foreign_proc).

:- type pragma_foreign_code_attributes
:- type pragma_foreign_proc_attributes

The functors for pragma_type
	foreign(Lang, BodyCode)
	foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl)
become
	foreign_code(Lang, BodyCode)
	foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl)

And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'.

compiler/*.m:
	Update the compiler to use the new names.
2001-04-03 03:20:33 +00:00
Tyson Dowd
477ecb18f6 Implement pragma foreign_code for Managed C++.
Estimated hours taken: 60

Implement pragma foreign_code for Managed C++.

Currently you can only write MC++ code if your backend is capable of
generating use MC++ as its "native" foreign language.  The IL backend is
the only backend that does this at the moment (the other backends have C
as their "native" foreign language).

Most of the machinery is in place to call from C to (normal) C++
but there is little work done on actually spitting out the C++ code into
a separate file.  The IL backend does this step already with managed C++.
The intention is to turn foreign_code for C++ into a pragma import
(which imports the C++ function from a separate file) and
foreign_code for C (which calls the imported function).  The C++ code
will be inserted into a separate file that is compiled using C linkage.

The important improvement this change gives is that you can write a
module with a C and a MC++ implementations side-by-side.  The target
backend will select the most appropriate foreign language to use.
You can override its choice using --use-foreign-language.  Later on
we will probably want more flexibility than just a single language
selection option).

This change also implements :- pragma foreign_decl, which allows header
file style declarations to be written in languages other than C.

compiler/code_gen.m:
	Reject code that is not C when generating LLDS.

compiler/export.m:
	Start renaming C as foreign.
	Reject code that is not C when generating exports.

compiler/foreign.m:
	A new module to handle foreign language interfacing.
	The bulk of the code for pragma import has been moved here from
	make_hlds.

compiler/globals.m:
	Convert foreign language names to foreign_language.
	This code has been moved closer to the similar conversion we do
	for target language names.
	Add globals__io_lookup_foreign_language_option to make it easier
	to deterministically lookup the options relating to foreign
	languages.


compiler/hlds_module.m:
	Move module_add_foreign_decl and module_add_foreign_body_code
	from make_hlds.m (where they were called module_add_c_header and
	module_add_c_code).

compiler/hlds_out.m:
	Write the foreign language out in HLDS dumps.

compiler/llds.m:
	Change foreign_header_info to foreign_decl_info.
	Change definitions of foreign_decl_code and foreign_body_code to
	include the language.

compiler/llds_out.m:
	Reject code that is not C when writing out LLDS.

compiler/make_hlds.m:
	Add foreign language information to the bodys and decls when
	creating them.
	Update error messages to refer to foreign code instead of C
	code.
	Use foreign.m to generate interfaces from the backend language
	to the foreign language.
	Hardcode C as the language for fact tables.

compiler/mercury_compile.m:
	Collect the appropriate foreign language code together for
	output to the backend.

compiler/intermod.m:
compiler/mercury_to_mercury.m:
	Output the foreign language string.
	Change a few names to foreign_code instead of c_code.

compiler/ml_code_gen.m:
	Filter the foreign language bodys and decls so that we only get
	the ones we are in (given by the use-foreign-language option).

compiler/mlds_to_c.m:
	Abort if we are given non C foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/mlds_to_ilasm.m:
	Abort if we are given non MC++ foreign language code to output
	(we might handle it here in future, or we might handle it
	elsewhere).

compiler/options.m:
compiler/handle_options.m:
	Add --use-foreign-language as a user option to control the
	preferred foreign language to use as the implementation of this
	module.
	Add backend_foreign_language as an internal option which stores
	the foreign language that the compiler will use as a default
	(e.g. the natural foreign language for the backend to use).
	Set the preferred backend foreign language depending on the
	target.

compiler/prog_data.m:
	Add managedcplusplus as a new alternative for the
	foreign_language type.
	Make c_header_code into foreign_decl.
	Give the foreign language for foreign_code as an attribute of
	the code.
	Write code to turn attributes into a list of strings (suitable
	for writing out by mercury_to_mercury).  This fixes what appears
	to be a bug in tabled_for_io -- the tabled_for_io attribute was not
	being written out.  Structure the code so this bug is
	difficult to repeat in future.

compiler/prog_io_pragma.m:
	Parse foreign_decl.
	Turn c_header_code into a special case of foreign_decl.

compiler/*.m:
	Remove the language field from pragma_foreign_code, it is now an
	attribute of the code.
	Various type and variable renamings.

tests/invalid/pragma_c_code_and_clauses1.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/warnings/singleton_test.exp:
	Update the tests to reflect the new error messages talking
	about :- pragma foreign_code rather than :- pragma c_code.
2000-11-17 17:48:52 +00:00
Zoltan Somogyi
07d6517521 Implement a general mechanism for suppressing selected aspects of execution
Estimated hours taken: 8

Implement a general mechanism for suppressing selected aspects of execution
tracing.

compiler/trace_params.m:
	This new file contains two abstract data types that define the
	parameters of the execution tracing system, and the operations
	on them.

	The two ADTs are the trace level (moved from globals.m) and a new one,
	trace_suppress_items, which replaces --no-trace-internal,
	--no-trace-redo and --no-trace-return, and provides additional
	capabilities requested by Erwan.

	Basically any given port can now be suppressed, with the exception of
	call (because the call event's layout structure is needed for
	implementing redo from any other event) and excp (because they are
	created on the fly by exception.m, and are not put into object
	code in the first place).

compiler/globals.m:
	Delete the stuff now migrated to trace_params.m. Make
	trace_suppress_items part of the globals structure.

compiler/code_gen.m:
compiler/trace.m:
	Allow the suppression of individual ports.

compiler/stack_layout.m:
	Allow the suppression of parts of layout structures.

compiler/*.m:
	Minor changes, mainly importing trace_params, to conform to the main
	modifications.

compiler/options.m:
	Delete --no-trace-internal, --no-trace-redo and --no-trace-return.
	Add --suppress-trace, but do not document it, since it is really
	intended only for implementors.

doc/user_guide.texi:
	Delete the documentation of --no-trace-internal, --no-trace-redo and
	--no-trace-return. Do not document it --suppress-trace, since it is
	really intended only for implementors. (The only reason why other three
	were documented is that most consumers of the users' guide then *were*
	implementors.)
2000-10-03 00:34:52 +00:00
Zoltan Somogyi
36fc174bed Make declarative debugging a trace level, not a separate option.
Estimated hours taken: 2

Make declarative debugging a trace level, not a separate option.

compiler/globals.m:
	Make trace_level an abstract data type. Define and export several
	functions that check whether the current trace level requires
	particular kinds of treatment.

compiler/options.m:
	Remove --trace-decl as an option.

compiler/*.m:
	Instead of checking for particular values of the trace level, use
	the functions now exported by globals.m.

tests/debugger/declarative/Mmakefile:
	Use the trace level to ask for declarative debugging.
2000-09-27 05:23:36 +00:00
Zoltan Somogyi
a1f326f4e9 Add an alternative to code_exprn that does eager code generation (code_exprn
Estimated hours taken: 140

Add an alternative to code_exprn that does eager code generation (code_exprn
always does lazy code generation). Its main advantages are that the new code
is significantly simpler, and that it does not generate unnecessary shuffling
code. Its main disadvantage, which is that it does not eliminate the creation
of unneeded cells, can be eliminated by switching on --unneeded-code.

For now, you can select the use of the new code generator with the
--no-lazy-code option (which was previously present but unused).
This will be made the default later, after I do more performance tests.

Var_locn contains stricter self-checks than code_exprn does. This required
modifications to some other parts of the code generator to ensure that the
self-checks do not fail unnecessarily. (This mostly took the form of explicitly
killing off dead variables before calling code_info__clear_all_registers, which
would complain about losing the last record of the value of a variable that was
alive as far as it knew.) To make my changes simpler, also took the opportunity
to simplify parts of the code generator which were handing around rvals that
in fact had to be wrappers around lvals, by handing around the lvals directly.

Testing this change also required fixing an old bug which prevented compiling
the library with -O1 --trace deep, together with the usual intermodule
optimization. The bug is that a library module reads predicates from
builtin.opt or private_builtin.opt, does not eliminate them because of the -O1,
and then tries to generate traced code for them. However, this fails because
the builtin modules contain some predicates that cannot be made to conform to
typeinfo-liveness, which is required by tracing.

compiler/var_locn.m:
	The new module that implements eager code generation.

compiler/follow_vars.m:
	Improve the follow_vars pass, since eager code generation requires
	better follow_vars information. We now generate correct information
	for generic calls, and record not only where some vars (e.g. those
	which appear as input arguments of following calls) should be put,
	but also which registers are not reserved for those variables and
	are thus available for other variables.

compiler/hlds_goal.m:
	Modify the follow_vars field of the goal_info to record the number
	of the first non-reserved register.

compiler/code_info.m:
 	Replace the general-purpose predicate code_info__cache_exprn, which
	associated a variable with an rval without generating code, with a set
	of special-purpose predicates such as code_info__assign_const_to_var
	and code_info__assign_cell_to_var, some of which can generate code.

	These new predicates and some older ones (e.g. code_info__setup_call)
	now choose at runtime whether to call code_exprn or var_locn. The
	basis for the decision is checking whether the code_info structure
	contains an exprn_info or a var_locn_info. This is decided in
	code_info__init based on the value of the lazy_code option, and
	maintained unchanged from then on.

	Rename some predicates to better reflect their current possible
	behaviors.

compiler/unify_gen.m:
	Call the new special-purpose predicates in code_info instead of
	code_info__cache_exprn.

	Replace an incorrect clause with a call to error, since that clause
	could never be invoked.

compiler/call_gen.m:
	Hand over the task of generating the args of generic calls to
	code_info, since it already has code to do the right thing, which
	includes reserving the registers to be used for the input args.

	Notify the rest of the code generator after the last use of
	non-forward-live variables, in order to avoid spurious calls to error
	(it is an error to clobber the last location of a live variable).

	Notify the rest of the code generator when generic calls overwrite
	registers, to allow the proper consistency checks to be made.

	If an output variable is singleton, then do not make it known to the
	code generator. It never will never become dead, and may thus cause a
	spurious compiler abort if its storage is ever clobbered.

	Export a predicate for use by follow_vars.

	Factor out some common code.

	Call the new preds in code_info where necessary.

compiler/pragma_c_gen.m:
	Notify the rest of the code generator after the last use of
	non-forward-live variables, in order to avoid spurious calls to error
	(it is an error to clobber the last location of a live variable).

	If an output variable is singleton, then do not make it known to the
	code generator. It never will never become dead, and may thus cause a
	spurious compiler abort if its storage is ever clobbered.

	When using var_locn, ensure that none of the input arguments of a
	model_semi pragma_c_code is assigned to r1. If we did, and the last
	reference to the value of that argument was after an assignment to
	SUCCESS_INDICATOR, the C compiler would be forced to generate code
	to shuffle the value of the argument out of the way.

compiler/code_exprn.m:
	Minor changes to return lvals directly instead of lvals wrapped inside
	rvals and to conform the new format of follow_vars.

	Do not include the registers reserved by follow_vars in the
	search for a spare register.

compiler/lookup_switch.m:
compiler/switch_gen.m:
	Fix an old bug that did not matter with code_exprn but does matter with
	var_locn: the branch end structure was being computed in the wrong
	place.

compiler/disj_gen.m:
	At the ends of non-last disjuncts, kill off the variables that we
	needed to know inside the disjunct but won't need to know after the
	disjunct, in order to avoid error messages about throwing away their
	state. The variables affected are those which are needed only by the
	resumption point of the next disjunct, not by enclosing resumption
	points or forward execution.

compiler/arg_info.m:
	Associate an lval, not an rval, with each argument.

compiler/*.m:
	Minor changes to conform to (a) the new format of follow_vars, (b)
	the replacement of rvals containing lvals by lvals.

compiler/code_util.m:
	Add some utility predicates for var_locn.m.

compiler/exprn_aux.m:
	Add some utility functions for var_locn.m.

	Export a predicate for var_locn.m.

compiler/handle_options.m:
	If --no-lazy-code is set, switch on the "optimizations" on whose
	presence it depends.

compiler/mercury_compile.m:
compiler/code_gen.m:
	Turn off tracing for predicates that don't obey typeinfo liveness
	for backend_by_preds and backend_by_phases respectively.

	Look up options in the globals structure in the module_info, not in the
	globals structure in the I/O state, since this is where we turn off
	tracing. (We should later make sure that other parts of the compiler
	are also consistent on this issue.)

compiler/stack_layout.m:
	Throw away any continuation_info structures that belong to predicates
	that don't obey typeinfo liveness.
2000-09-16 00:08:27 +00:00
Tyson Dowd
c192d50143 Add preliminary support for a new pragma:
Estimated hours taken: 15

Add preliminary support for a new pragma:

:- pragma foreign_code(LanguageString, .... <same args as c_code>).

This is intended to be the eventual replacement of pragma c_code.
Presently the only valid language is "C".
The existing pragma c_code is simply turned into pragma foreign_code.

pragma foreign_code is not a supported pragma at the moment.  There are
several other changes that are intended (for example, foreign_code will
be impure by default).

This change also changes the HLDS goal pragma_c_code/7 to
pragma_foreign_code/8 where the extra argument is the foreign language.

Any code currently generating output for pragma C code simply checks
that the foreign language is set to "c".  Since this is the only
alternative of the type foreign_language, it will always succeed.
However when new alternatives are added it should be fairly easy to find
where the changes need to be made.

Some type names and predicate names have also been updated, however
there are many more that haven't yet been touched.

compiler/prog_io_pragma.m:
	Accept the new syntax.	Turn the old syntax into the new item.

compiler/hlds_goal.m:
	Change pragma_c_code/7 to pragma_foreign_code/8.
	Define the foreign_language type.

compiler/llds.m:
	Change user_c_code/2 to user_foreign_code/3.

compiler/*.m:
	Update the rest of the compiler to handle these types.
	Make a few small changes to update variable names, predicate
	names and type names.
2000-08-09 07:48:04 +00:00
Fergus Henderson
d551dd1dc9 Handle quantification analysis of bi-implication (`<=>') goals correctly.
Estimated hours taken: 10

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

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

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

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

compiler/purity.m:
	Eliminate double negation.

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

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

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

tests/hard_coded/Mmakefile:
tests/hard_coded/quantifier2.m:
tests/hard_coded/quantifier2.exp:
	A regression test for the above change.
1999-10-25 03:53:14 +00:00
Simon Taylor
2725b1a331 Aditi update syntax, type and mode checking.
Estimated hours taken: 220

Aditi update syntax, type and mode checking.

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

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

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

	Add a `lambda_eval_method' field to lambda_goals.

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

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

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

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

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

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

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

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

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

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

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

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

	Add `aditi_top_down' to the type `marker'.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

compiler/make_hlds.m:
	Parse Aditi updates.

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

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

compiler/typecheck.m:
	Typecheck Aditi builtins.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

doc/reference_manual.texi:
	Document Aditi updates.

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

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

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

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

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

tests/valid/aditi.m:
tests/invalid/aditi.m:
	Cut down version of extras/aditi/aditi.m to provide basic declarations
	for Aditi compilation such as `aditi__state' and the modes
	`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
	somewhere would remove the need for these.
1999-07-13 08:55:28 +00:00
Thomas Conway
5c955626f2 These changes make var' and term' polymorphic.
Estimated hours taken: 20

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

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

NEWS:
	Mention the changes to the standard library.

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

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

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

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

compiler/*.m:
	Thousands of boring changes to make the compiler type correct
	with the different types for type, program and inst vars and
	varsets.
1998-11-20 04:10:36 +00:00
Zoltan Somogyi
8a0ceb49aa This checkin has several major purposes, set out in the sections below,
Estimated hours taken: 240

This checkin has several major purposes, set out in the sections below,
all connected with the implementation of the new debugger command set.

DOCUMENT NEW DEBUG COMMAND SET

doc/user_guide.texi:
	Add a new section on the debugger. The description of the commands
	is complete, but some of the background sections, and the section
	about how to build debuggable executables, are not yet done.

	Update the documentation of the tracing options.

doc/generate_mdb_doc:
	A new shell script that automatically converts some of the new
	sections of the user guide into the online documentation of the
	debugger.

doc/mdb_categories:
	The fixed initial part of the online documentation.

doc/Mmakefile:
	Add rules for creating mdb_doc, the file that is the online
	documentation of the debugger, and for installing it together
	with mdbrc.

Mmake.common.in:
	Define INSTALL_DOC_DIR for doc/Mmakefile.

scripts/mdbrc.in:
	A debugger command script that reads in the online documentation
	and then defines some standard aliases.

configure.in:
	Define the variable that scripts/mdb.in and scripts/mdbrc.in use
	to find the right files, and get configure to perform the
	substitutions.

configure.in:
scripts/mdb:
scripts/mdb.in:
	Replace mdb with mdb.in. Mdb is now created during configuration
	from mdb.in, filling in the name of the file that contains the default
	debugger initialization commands.

util/info_to_mdb.c:
	A program that does most of the work involved in automatically
	converting user guide sections into online documentation.
	(This couldn't easily be written in sh, because sh's read
	command has no notion of pushback.)

util/Mmakefile:
	Add info_to_mdb to the list of targets.

tools/bootcheck:
	Make sure that the tests in tests/debugger are executed with an
	initialization setup that is equivalent to what users will see
	by default.

REORGANIZE TRACING OPTIONS

compiler/globals.m:
compiler/handle_options.m:
compiler/options.m:
compiler/trace.m:
	Reorganize the handling of trace levels around the new options
	--trace-internal, --trace-redo, and --trace-return.

compiler/*.m:
	Use the new ways of getting at trace levels.

tests/hard_coded/typeclasses/Mmakefile:
	s/--trace all/--trace deep/

SUPPORT RETRY

compiler/trace.m:
	After every call to MR_trace(), emit code that checks whether it
	should jump away, and if yes, performs the jump. This is used to
	implement retry. (The debugger cannot execute the jump itself
	because it is in the wrong C stack frame.)

compiler/llds.m:
compiler/continuation_info.m:
compiler/stack_layout.m:
	Modify the data structures that record information about live
	value at program points, to record the identity of each variable.
	This is necessary for the implementation of the restart command,
	since we do not want to confuse two distinct variables just because
	they have the same name. For example, a variable whose name is X
	and number is 5 is now recorded in the name array as "5:X".

	Clean up the data structure a bit, so that we don't have to store
	dummy names for values that are not variables.

compiler/*.m:
	Minor changes to conform to the data structure changes.

runtime/mercury_stack_layout.h:
	Redefine an existing macro to strip away the initial number: prefix
	from the "name" of a variable (keeping its original function on
	changed data), and add a new one to access the raw unstripped data.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

runtime/mercury_layout_util.h:
	Add an extra function, MR_get_register_number, for use by retry.

USE FIXED STACK SLOTS FOR TRACE INFO

compiler/code_gen.m:
compiler/code_info.m:
compiler/live_vars.m:
compiler/trace.m:
	If execution tracing is enabled, reserve the first few stack slots
	to hold the event number of the call event, the call number, the
	call depth, the redo layout structure address (if generating redo
	events) and the from_full flag at the time of call (if we are doing
	shallow tracing). By allocating the first four of these to fixed stack
	slots, the debugger knows where to look for them without having
	to be told. It finds out the location of the fifth, if needed,
	from a new slot in the proc layout structure. (It is not possible
	to allocate all five to fixed stack slots without wasting stack space
	in some cases.)

compiler/trace.m:
	Remove from the call to MR_trace the parameters that are now in fixed
	stack slots, since MR_trace can now look them up itself.

compiler/continuation_info.m:
compiler/stack_layout.m:
	Add an extra field to the proc_layout_info. If the module is shallow
	traced, this field says which stack slot holds the saved value of
	MR_from_full. If it is not shallow traced, this field says that
	there is no such stack slot.

runtime/mercury_stack_layout.h:
	Add macros for accessing the fixed stack slots holding the event
	number of the call event, the call number, the call depth, and,
	at a redo event, the redo layout structure address.

	Support the new field in proc layouts that gives the location of the
	from-full flag (if any).

runtime/mercury_trace_base.[ch]:
trace/mercury_trace.[ch]:
	Remove the call number and call depth arguments from MR_trace
	and its avatars, since this info is now in fixed stack slots
	in every procedure that can call MR_trace. This should reduce
	the size of the executable significantly, since there are lots
	of calls to MR_trace.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

START NUMBERING FRAMEVARS FROM ONE

compiler/code_info.m:
compiler/live_vars.m:
compiler/llds_out.m:
compiler/trace.m:
	Start numbering framevars from 1 internally to the compiler;
	the runtime already starts from 1. This simplifies several tasks.

ADD REDO EVENTS

compiler/trace.m:
compiler/code_gen.m:
	Before the code that executes "succeed()", emit code to push a
	a temp nondet frame whose redoip points to a label in the runtime
	that calls MR_trace for a REDO event and then fails, provided
	--trace-redo is set.

compiler/llds.m:
	Add a new code address constant, do_trace_redo_fail, which stands
	for the address in the trace system to which calls MR_trace for
	the redo event and then fails.

compiler/trace.m:
compiler/llds_out.m:
	Provided we are doing redo tracing, fill in the slot that holds
	the layout information for the REDO event.

compiler/*.m:
	Minor changes to conform to handle the new code address constant.

browser/debugger_interface.m:
	Add redo to trace_port_type.

runtime/mercury_trace_base.[ch]:
	Add a C module containing the code that calls MR_trace for REDO
	events.

ENSURE THAT INPUT ARGUMENTS ARE ALWAYS VISIBLE

compiler/trace.m:
	When generating the set of live variables at internal ports,
	the variables that are in the pre-death set of the goal into which
	we are entering may not be available. However, the variables in the
	pre-death set that are also in the resume vars set will be available,
	so now include info about them in the layout structure for the event.
	Since with tracing the non-clobbered input args are in all resume vars
	sets, this ensures that these input args will be available from all
	internal events.

compiler/code_info.m:
	Export a previously internal predicate (current_resume_point_vars)
	to make this possible.

BUG FIX: WANT RETURN LAYOUTS

compiler/globals.m:
compiler/call_gen.m:
compiler/code_info.m:
compiler/mercury_compile.m:
	Add a new pred globals__want_return_layouts, which says whether the
	compiler should generate layout structures for call returns. This pred
	centralizes the several previous copies of the test. One of those
	copies (the one in call_gen) was faulty, leading to a bug: in the
	presence of execution tracing but the absence of accurate gc,
	information about the variables that are live at the call return
	wasn't being gathered properly.

BUG FIX: #include mercury_trace_base.h

compiler/llds_out.m:
	#include mercury_trace_base.h, not mercury_trace.h, since now
	mercury_trace_base.h defines everything directly accessible from
	modules compiled with tracing.

RECAST MERCURY_TRACE_UTIL AS MERCURY_LAYOUT_UTIL

runtime/mercury_trace_util.[ch]:
runtime/mercury_layout_util.[ch]:
	Rename this module from trace_util to layout_util, since it is also
	used by the native garbage collector. Remove "trace" from the names
	of functions.

	Get rid of the global variable MR_saved_regs, and instead thread
	a pointer to this data structure through the relevant functions
	as an extra argument.

	Add a lot more documentation in the header file.

runtime/Mmakefile:
	Reflect the module rename.

runtime/*.c:
	Refer to the new module.

DELETE EASY-TO-MISUSE MACROS

runtime/mercury_stacks.h:
	Delete the based_framevar and based_detstackvar macros, since their
	continued use can lead to off-by-one errors, and the saved_framevar
	and saved_detstackvar macros, since they are no longer used.

runtime/*.c
	Update any references to any macros removed from mercury_stacks.h.

MISC RUNTIME CHANGES

runtime/mercury_trace_base.[ch]:
trace/mercury_trace*.[ch]:
	Make typedef'd names conform to the naming convention.

	Make MR_trace_call_{seqno,depth} consistently Unsigned, rather than
	sometimes Word and sometimes Unsigned.

FIX BUG: MAKE THE DEBUGGER PRINT TO STDOUT, NOT THE CURRENT STREAM

library/io.m:
	Export to C code the predicates that return the identities and types
	of stdin, stdout and stderr, as well as io__print/[34].

library/std_util.m:
	Export to C code a predicate that returns the type_info for the
	type stdutil:type_info. This type_info is required if C code
	wants to invoke make_permanent on any type_info structure,
	as the debugger does.

runtime/mercury_init.h:
	Add extern declarations for the C functions now exported from io.m.

runtime/mercury_wrapper.[ch]:
	Add new global variables to hold the addresses of these C functions.

runtime/mercury_layout_util.c:
	Use indirect calls through these global variables to print Mercury
	values, instead of lower-level code.

util/mkinit.c:
	Assign the addresses of the functions exported from io.m to the
	global variables defined in mercury_wrapper.h.

BUG FIX: STACK TRACE FUNCTIONS DEPEND ON THE LABEL TABLE

runtime/mercury_stack_trace.c:
	On entry to any of the functions exported from this module,
	ensure that the label table is loaded by calling do_init_modules.
	Without a filled-in label table, the stack trace will not be able to
	find any stack layout info.

BUG FIX: REMOVE BROWSER/*.C

configure.in:
	When removing .c files generated by the C compiler, remove those
	in the browser directory as well as the compiler, library and
	profiler directories.

IMPLEMENT NEW DEBUGGER COMMAND SET

runtime/mercury_stack_trace.[ch]:
	Factor out the code that prints the id of a procedure into a function
	of its own, so that it can also be used from the debugger, ensuring
	appearance commonality.

	Add more documentation in the header file.

trace/mercury_trace_internal.c:
	Implement the proposed command set. Command names are now words,
	and several commands now have options allowing the user to override
	the default print level or strictness of the command, or the
	invocation conditions or action of a break point. Allows control
	over command echoing and the scrolling of sequences of event reports.
	Supports aliases, command file sourcing etc. Implements the retry
	command, using the info in the fixed stack slots.

trace/mercury_trace.[ch]:
	Extend the trace controls to support the new functionalities
	required by the new debugger language, which are print levels,
	variable-strictness commands, a more flexible finish command,
	and the retry command.

	Pass the command structure to MR_trace_event_report, since
	the user can now forcibly terminate the scrolling of reports.

trace/mercury_trace_alias.[ch]:
	New module to manage aliases for the debugger.

trace/mercury_trace_help.[ch]:
	New module to interface to browser/help.m.

trace/mercury_trace_spy.[ch]:
	New module to manage break points. The test of whether an event
	matches a break point is now much more efficient than before.
	The new module also allows several breakpoints with different
	actions and different invocation conditions (e.g. all ports,
	entry port, interface ports or specific (possibly internal) port)
	to be defined on the same procedure.

trace/mercury_trace_tables.[ch]:
	New module to manage a table of the debuggable modules, in which
	each such module is linked to the list of the layouts of all the
	procedures defined in that module. This information allows the
	debugger to turn the name of a predicate/function (possibly together
	with its arity and mode number) into the procedure layout structure
	required by the spy point module. Eventually it may also be useful
	in supplying lists of identifiers for command line completion.

	Modules for which no stack layout information is available will
	not be included in the table, since do_init_modules will not
	register any labels for them in the label table.

trace/Mmakefile:
	Mention the new files.

runtime/mercury_array_macros.h:
	A new file holding macros that can be useful in more than one module.

runtime/Mmakefile:
	Mention the new file.

runtime/mercury_conf.h.in:
	Mention a new configuration macro, MR_CANNOT_USE_STRUCTURE_ASSIGNMENT,
	used by runtime/mercury_array_macros.h.

configure.in:
	Find out whether we need to define MR_CANNOT_USE_STRUCTURE_ASSIGNMENT.

ADD TRACE DEPTH HISTOGRAMS

runtime/mercury_conf_param.h:
	Document MR_TRACE_HISTOGRAM.

runtime/mercury_trace_base.[ch]:
	Define the data structures for the histogram, and print the histogram
	when a traced program exits if MR_TRACE_HISTOGRAM is set.

trace/mercury_trace.[ch]:
	If MR_TRACE_HISTOGRAM is defined, record a count of the number of
	events at each depth. This information can help us evaluate space-time
	tradeoffs.

FACTOR OUT SHELL CODE HANDLING GRADE IMPLICATIONS

scripts/final_grade_options.sh-subr:
	A new file to contain any code that implements implications between
	grade flags; currently implements the implication debug -> use trail.

scripts/mgnuc.in:
scripts/ml.in:
	Replace the code that is now in final_grade_options.sh-subr with
	an inclusion of final_grade_options.sh-subr.

configure.in:
	Handle final_grade_options.sh-subr as {init,parse}_grade_options.sh-subr
	are handled.

SIMPLIFY THE MAINTAINANCE OF CONSISTENCY BETWEEN DEBUGGER CODE AND DOCUMENTATION

doc/Mmakefile:
	Add rules for creating mdb_command_list, a C code fragment
	that can included manually in trace/mercury_trace_internal.c
	to supply the list of valid commands, and mdb_command_test.inp,
	which is a list of invalid invocations of debugger commands,
	which tests whether the help message for such invocations
	can be located as expected.

doc/generate_mdb_command_list:
doc/generate_mdb_command_test:
	Awk scripts to create mdb_command_list and mdb_command_test.inp
	respectively from mdb_doc.

tools/bootcheck:
	Copy mdb_command_test.inp from doc to tests/debugger.

tests/debugger/Mmakefile:
	Add a new test that checks whether we get an internal error, unable
	to locate the right help node, for each invalid command invocation in
	mdb_command_test.inp.

UPDATE TEST CASES

tests/debugger/Mmakefile:
	Reenable queens. Conform to the new set of options.

tests/debugger/*.inp:
tests/debugger/*.exp:
	Update the inputs and expected outputs of the debugger test cases
	to use the new command set and output formats.
1998-10-16 06:20:28 +00:00
Zoltan Somogyi
4ab3f397b1 Allow the debugger to print the values of variables in ancestors
Estimated hours taken: 20

Allow the debugger to print the values of variables in ancestors
of the current call. This requires knowledge about which named variables
are live at call return sites. Providing this information properly required
fixing the interaction of execution tracing and accurate garbage collection.

compiler/globals.m:
	Introduce a new trace level, so that there are now four:
	none, interface, interface_ports (corresponding to the existing
	three levels) and the new level interface_ports_returns,
	each of which requires all the information required by lower
	levels.

	Make the trace level abstract, since in the future we may want to
	introduce trace levels for new combinations, e.g. interfaces and
	returns but not internal ports. Introduce the necessary new
	predicates.

compiler/continuation_info.m:
	Redefine internal_label_info to allow us to record separate info about
	the sets of vars needed at (a) internal ports of execution tracing
	and at (b) call return points for accurate gc or (now) uplevel
	printing during execution tracing. Neither is a subset of the other,
	and they need to be treated differently.

compiler/mercury_compile.m:
	Gather information about vars at return labels if the trace level
	requires uplevel printing capability, even if agc is off.

compiler/stack_layout.m:
	Fix the handling of labels which are needed both by agc and by
	execution tracing. If information at a return label is needed only
	by uplevel printing in execution tracing and not by agc, then
	discard all info about lvals which do not hold named variables
	or their typeinfos (in fact we keep all typeinfos at the moment).
	If a label is both the label of a port and a return label, we
	include in the layout structure the union of the information
	recorded for the two roles.

	Sort the var_info vector before using it to generate layout
	structures in an attempt to make llds_common more effective
	and to make lists of variables printed by the debugger look better.

	Record a distinguished value when there is no info about the vars
	live at a label, rather than (incorrectly) recording that there
	are no live variables. Before up-level printing, the lie was harmless;
	now it isn't.

	Remove the label number from return label layouts, since the tracer
	isn't expecting it. It used to be included for debugging purposes
	if the label was for agc, but it is possible for a label to be needed
	both for agc and for execution tracing. If Tyson finds he needs the
	label number, it can be easily turned back on for all label layouts.

compiler/code_info.m:
	Conform to the new definition of internal_label_info.

	Rename an internal pred for clarity.

	Rename some bool parameter to correctly reflect their new meaning.

compiler/*.m:
	Trivial changes, mostly due to making trace_level an abstract type.

runtime/mercury_stack_layout.h:
	Remove the label number from return label layouts, since the tracer
	isn't expecting it.

runtime/mercury_stack_trace.[ch]:
	Add a new function that returns the label layout structure at the
	Nth ancestor return continuation, together with the values of
	sp and curfr at that point. This required changing MR_stack_walk_step
	to step from an entry layout only to the return label layout.

runtime/mercury_stacks.h:
	Add macros that let us access detstackvars and framevars based on
	these synthesized values of sp and curfr.

runtime/mercury_trace_util.[ch]:
	Generalize several functions to allow them to use synthesized
	(as opposed to saved) values of sp and curfr in looking up values.

	Retain functions with the original names and signatures that call
	the new, general versions with the necessary additional parameters.

runtime/mercury_trace_internal.c:
	Add a new command that sets the "ancestor level". For example,
	"l 2" sets it to 2, which means that the command "v" and "p" will
	refer to the grandparent of the current call. The ancestor level
	persists while the debugger is at the current event; after that
	it is reset to 0.

	The implementation involves calling the new function in
	mercury_stack_trace.c and the generalized functions in
	mercury_trace_util.c.

	Also add a deliberately undocumented extra command, X, which
	prints the stack pointers.

NEWS:
	Add a reminder about removing the X command before release.

tests/debugger/*
	Update half the test cases (those which assume a non-debug-grade
	library) to conform to the changes in the debugger interface.
	The others will need to be updated later.
1998-06-18 06:08:37 +00:00
Thomas Conway
a70b59e83c Add a test to find the number of words needed to represent a
configure.in:
        Add a test to find the number of words needed to represent a
        synchronization term.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

runtime/mercury_engine.h:
        declare the mercury_engine structure.

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

scripts/init_grade_options.sh-subr
        add thread_safe

scripts/mgnuc.in
        add THREAD_OPTS

scripts/ml.in:
        add THREAD_LIBS
1998-06-09 02:16:31 +00:00
Zoltan Somogyi
af6f18ab3f Fergus's recent change to the handling of some builtins broke the tracing
Estimated hours taken: 20

Fergus's recent change to the handling of some builtins broke the tracing
of those builtins. The following changes are a fix for this.

compiler/polymorphism.m:
	Export the predicate that checks whether a predicate is a builtin
	that lacks the usually necessary typeinfos.

	Comment out a misleading and in any case not very useful progress
	message.

compiler/liveness.m:
	Turn off type_info liveness for builtins without typeinfos.
	Since these builtins establish no gc points and shouldn't be
	execution traced, this is OK.

	Make type_info liveness part of live_info, since it can now be
	incorrect to look up the value of the option. (This may yield
	a speedup.)

compiler/live_vars.m:
compiler/store_alloc.m:
	Pass the pred_id to initial_liveness to liveness.m can do the test.

compiler/passes_aux.m:
	Add a new traversal type that passes along the pred_id.

compiler/mercury_compile.m:
	Turn off execution tracing for the modules builtin.m and
	private_builtin.m. The latter contains the interface predicates
	for the builtins without typeinfos. Since the interface predicates
	also lack the typeinfos, the compiler would get an internal abort
	if we left execution tracing on.

	In any case, these two modules contain stuff that users should
	consider language builtins, which means they should not be execution
	traced (they can still be stack traced in the right grade).

	Use the new traversal type for the modules that now need the pred_id.

compiler/globals.m:
	Allow the trace level to be set from outside, in this case
	mercury_compile.m.

The next batch of changes have to do with adding a stack dump command
to the debugger. Since debugging is possible even in non-debug grades,
this in turn requires allowing stack tracing to work in non-debug grades,
on programs in which only some modules are compiled with execution
(and hence stack) tracing.

compiler/llds_out.m:
compiler/mercury_compile.m:
runtime/mercury_conf_param.h:
	Llds_out used to output "#include <mercury_imp.h>" as the first
	substantive thing in the generated C file. The set of #define
	parameters in effect when mercury_imp.h is processed determines
	whether the macros that optionally register stack layouts for label
	actually do so or not. The values of these parameters are derived
	from the grade, which means that with this setup it is not possible
	for a non-debug grade program to register its stack layouts in the
	label table.

	The new version of llds_out looks up the option that says whether
	this module is compiled with execution tracing or not, and if it is,
	it generates a #define MR_STACK_TRACE_THIS_MODULE *before* the #include
	of mercury_imp.h. This causes mercury_conf_param.h, included from
	mercury_imp.h, to define the macros MR_USE_STACK_LAYOUTS and
	and MR_INSERT_LABELS, which in turn cause stack layouts for labels
	in this module to be generated and to be inserted into the label
	table, *without* changing the grade string (this last part is why
	we do not simply define MR_STACK_TRACE).

	Use the same mechanism to #include mercury_trace.h when doing
	execution tracing, since it is simpler than the mechanism we
	used to use (mercury_compile.m including the #include in a list
	of C header file fragments).

compiler/mercury_compile.m:
runtime/mercury_conf_param.h:
	Split the MR_NEED_INITIALIZATION_CODE macro into two parts.
	The first, MR_MAY_NEED_INITIALIZATION, now controls whether
	initialization code makes it into the object file of a module.
	The second, MR_NEED_INITIALIZATION_AT_START, determines whether
	the initialization code is called before main/2.

	When a module is compiled with execution tracing, the macro
	MR_INSERT_LABELS turns on MR_MAY_NEED_INITIALIZATION but not
	MR_NEED_INITIALIZATION_AT_START. The debugger will make sure
	that the initialization code has been called before it tries
	to do a stack dump (which needs the initialization code to have
	been executed, because it needs labels to have been put into the label
	table so that from a return address it can find the layout of the
	proc to which it belongs).

	Define MR_NEED_INITIALIZATION_AT_START if PROFILE_TIME is defined,
	since if PROFILE_TIME is defined mercury_wrapper.c calls init_modules.
	The fact that MR_NEED_INITIALIZATION_CODE didn't used to be defined
	when PROFILE_TIME was defined was, I believe, a bug, which was
	not detected because we do not turn on PROFILE_TIME without also
	turning on PROFILE_CALLS.

runtime/mercury_stack_trace.[ch]:
	Change the way stack dumps are done, to make it possible to
	print stack dumps from the debugger and to use trivial run-length
	encoding on the output (so that 100 consecutive calls to p
	yield the line "p * 100", rather than 100 lines of "p").

	The stack routine now returns an indication of whether the stack dump
	was fully successful, and if not, a description of the reason why not.
	This requires knowing when we have found the end of the stack dump,
	so we provide a global variable, MR_stack_trace_bottom, which
	mercury_wrapper.c will set to global_success, the address main/2
	goes to on success.

	s/multidet/multi/

runtime/mercury_wrapper.c:
	Set MR_stack_trace_bottom to the address of globals_success.
	Use MR_NEED_INITIALIZATION_AT_START to decide whether to call
	do_init_modules.

runtime/mercury_stacks.h:
	Provide variants of detstackvar(n) and framevar(n) that look up sp and
	curfr in an array of saved regs, for use by the debugger.

runtime/mercury_trace_util.c:
	Use the new variants of detstackvar(n) and framevar(n). This fixes
	an old bug on SPARCs.

runtime/mercury_trace_internal.c:
	Completely reorganize the way debugger commands are handled.
	Centralize reading in command lines, and the breaking up of command
	lines into words. The command names are the same as they were,
	but command syntax is now much easier to change.

	Add a new command "d" to dump as much of the stack as the available
	information will allow.

runtime/mercury_goto.h:
	Cosmetic changes to avoid the use of two different conditional
	compilation layout styles.

util/mkinit.c:
	Since we cannot know when we generate the _init.c file whether any
	modules will be compiled with execution tracing and will thus need
	stack tracing, we must now include in the generated _init.c file the
	code to call the initialization functions in all the modules, even if
	MR_NEED_INITIALIZATION_AT_START is not set, since init_modules
	can be called later, from the debugger. (We should be able to
	use the same approach with the accurate collector.)
1998-06-08 08:27:15 +00:00
Zoltan Somogyi
d10af74168 This change introduces interface tracing, and makes it possible to successfully
Estimated hours taken: 50

This change introduces interface tracing, and makes it possible to successfully
bootstrap the compiler with tracing (either interface or full).

compiler/options.m:
	Change the bool options --generate-trace into a string option --trace
	with three valid values: minimal, interface and full. The last two mean
	what they say; the intention is that eventually minimal will mean
	no tracing in non-tracing grades and interface tracing in tracing
	grades.

compiler/globals.m:
	Add a new global for the trace level.

compiler/handle_options.m:
	Convert the argument of --trace to a trace level.

	Use only consistent 4-space indentation in the deeply nested
	if-then-else.

compiler/trace.m:
	Implement interface tracing.

	Rename trace__generate_depth_reset_code as trace__prepare_for_call,
	since it does more than reset the depth if this module is compiled
	with interface tracing.

	Do not check whether tracing is enabled before calling MR_trace;
	let MR_trace make the check. This trades increased non-tracing
	execution time for a substantial code size reduction (which may
	in turn benefit execution time).

compiler/call_gen.m:
	Call trace__generate_depth_reset_code by its new name.

compiler/code_info.m:
	Fix a bug in the handling of non/semi commits. When entering a commit,
	we used to push a clone of whatever the top failure continuation was.
	However, the resume setup for this continuation could have started
	with a label that assumed that the resume vars were in their original
	locations (which are often registers), whereas the method of
	backtracking to that point only guarantees the survival of stack slots,
	not registers.

	(This bug caused two lines of incorrect code to be generated among
	the approx 30 million lines of code in the stage 2 compiler when
	compiled with tracing.)

	Fix another bug (previously untriggered as far as I know) in the
	handling of multi/det commits. This one was breaking the invariant
	that the resume vars set of each entry on the failure continuation
	stack included the resume vars set of every other entry below it,
	which meant that the values of these resume vars were not guaranteed
	to be preserved.

compiler/stack_layout.m:
	Make layout structures local to their module. They are not (yet)
	referred to by name from other modules, and by declaring them
	to be global we caused their names to be included even in stripped
	executables, adding several megabytes to the size of the binary.
	(The names are not stripped because a dynamically linked library
	may want to refer to them.)

	Change the mercury_data__stack_layout__ prefix on the names of
	generated globals vars to just mercury_data__layout__. It is now
	merely too long instead of far too long.

	Include the label number in the label layout structure and the number
	of typeinfo variables in a var_info structure only with native gc.
	Their only use is in debugging native gc.

	Fix some documentation rot.

compiler/llds.m:
	Add a new field to the pragma_c instruction that says whether the
	compiler-generated C code fragments access any stack variables.

compiler/frameopt.m:
	Use the new field in pragma_c's to avoid a bug. Because frameopt was
	assuming that the pragma_c instruction that filled in the stack slots
	containing the call sequence number and depth did not access the stack,
	it moved the pragma_c before the incr_sp that allocates the frame
	(it was trying to get it out of the loop).

compiler/*.m:
	Minor changes to set or ignore the extra field in pragma_c, to refer
	to layout structures via the new prefix, or to handle the --trace
	option.

doc/user_guide.texi:
	Update the documentation for --trace.

runtime/mercury_types.h:
	Add the type Unsigned.

runtime/mercury_goto.h:
	Use the shorter layout prefix.

runtime/mercury_stack_layout.h:
	Use the shorter layout prefix, and include the label number only with
	native gc.

runtime/mercury_trace.[ch]:
runtime/mercury_trace_internal.[ch]:
runtime/mercury_trace_external.[ch]:
runtime/mercury_trace_util.[ch]:
	Divide the old mercury_trace.[ch] into several components, with one
	module for the internal debugger, one for the interface to the
	external debugger, one for utilities needed by both. Mercury_trace.c
	now has only the top-level stuff that steers between the two
	debuggers.

runtime/mercury_trace.[ch]:
	Add the new global variable MR_trace_from_full. Before each call,
	the calling procedure assigns TRUE to this variable if the caller
	is fully traced, and FALSE otherwise. Interface traced procedures
	generate trace events only if this variable is TRUE when they are
	called (fully traced callee procedures ignore the initial value of
	the variable).

	Make MR_trace return immediately without doing anything unless
	tracing is enabled and a new extra argument to MR_trace is TRUE.
	This extra argument is always TRUE for trace events in fully traced
	procedures, while for trace events from interface traced procedures,
	its value is set from the value of MR_trace_from_full at the time
	that the procedure was called (i.e. the event is ignored unless the
	interface traced procedure was called from a fully traced procedure).

runtime/mercury_trace.[ch]:
runtime/mercury_trace_internal.[ch]:
	For global variables that are stored in stack slots, make their type
	Word rather than int.

	Use a new function MR_trace_event_report instead of calling
	MR_trace_event with a NULL command structure pointer to indicate
	that the event is to be reported but there is to be no user
	interaction.

	Use %ld formats in printfs and casts to long for better portability.

runtime/mercury_trace_internal.c:
	Save trace-related globals across calls to Mercury library code
	in the debugger, since otherwise any trace events in this code
	could screw up e.g. the event number or the call number sequence.

	Create separate functions for printing port names and determinisms.

runtime/mercury_wrapper.h:
	Disable the tracing of the initialization and finalization code
	written in Mercury.

runtime/Mmakefile:
	Update for the new source and header files.

tests/debugger/{debugger_regs,interpreter,queens}_lib.{m,inp,exp}:
	One new copy of each existing test case. These ones are intended
	to be used when the stage 2 library is compiled with tracing, which
	affects the tests by adding events for the library procedures called
	from the test programs.

	The .m files are the same as before; one of the .inp files is a bit
	different; the .exp files reflect the correct output when the library
	is compiled with full tracing.

tests/debugger/Mmakefile:
	Provide separate targets for the new set of test cases.

	Use --trace full instead of --generate-trace.

tests/debugger/runtests:
	Try both the new set of test cases if the old set fails, and report
	failure only if both sets fail. This is simpler than trying to figure
	out which set should be really tested, and the probability of a false
	positive is negligible.
1998-05-16 07:31:33 +00:00
Zoltan Somogyi
67d8308260 Same as previous message. 1998-04-08 11:36:13 +00:00
Zoltan Somogyi
0f41ebf9e1 When deciding where to put the known variables at the end of a branched
Estimated hours taken: 2

store_alloc.m:
	When deciding where to put the known variables at the end of a branched
	control structure, and looking at a variable not in the follow-vars
	set, prefer putting the variable into its stack slot instead of a
	free register. The semantics of the follow-vars set says that this
	variable likely won't be used before the next call. Even if follow-vars
	is not turned on, prefer putting variables in their stack slots
	to putting them in non-real registers.
1998-04-02 03:04:06 +00:00
Andrew Bromage
b5dfd26ebd Miscellaneous small changes.
Estimated hours taken: 1.5

Miscellaneous small changes.

compiler/modes.m:
	Fix a couple of mode errors which were caught by the new mode
	checker: use of clobbered mode_infos.

compiler/simplify.m:
	Optimise away unifications of the form X = X.  (These can be
	created by excess assignment elimination.)

compiler/follow_vars.m:
compiler/hlds_goal.m:
compiler/inst_match.m:
compiler/prog_data.m:
compiler/store_alloc.m:
	Minor documentation fixes.
1998-03-24 00:06:59 +00:00
Simon Taylor
d0085d8119 Assorted changes to make the HLDS type and mode correct
Estimated hours taken: 45

Assorted changes to make the HLDS type and mode correct
after lambda expansion. The HLDS is still not unique mode
correct after common structure elimination.

compiler/det_analysis.m
	Make sure the inferred_determinism field of the proc_info is filled
	in correctly for imported procedures and class methods.

compiler/mode_util.m
	Fix a bug in recompute_instmap_delta_call to do with unreachable
	instmaps. This caused an abort a couple of months ago when
	compiling with --deforestation (not yet committed), but
	can't currently be reproduced.

compiler/hlds_pred.m
compiler/lambda.m
	Add a field to the proc_info to record which args_method
	should be used for this procedure. Procedures directly
	called by do_call_*_closure must be compiled with
	the `compact' argument convention to avoid the need to permute
	the arguments so inputs come before outputs.

compiler/lambda.m
compiler/higher_order.m
	Remove permutation of argument variables of lambda expressions
	so the HLDS is type and mode correct and mode analysis can
	be rerun. Otherwise, rerunning mode analysis will fail on
	tests/hard_coded/ho_order.m.

compiler/arg_info.m
	Added arg_info__ho_call_args_method which returns
	an args_method which can always be directly called by
	do_call_*_closure (`compact').
	Added arg_info__args_method_is_ho_callable to check that
	a given args_method can be directly called.

compiler/unify_gen.m
	Abort if a closure is created for a procedure compiled
	with the simple argument convention.

compiler/hlds_goal.m
compiler/lambda.m
	Mode analysis was not storing the non-locals list on which the
	uni_modes field of the construction of a lambda goal was computed.
	If the nonlocals were renamed, the sort order could change, and
	the non-locals could be incorrectly matched with the arguments
	of the introduced lambda expression, causing a mode error. The
	argument list is now stored.
	This caused rerunning mode-checking on tests/valid/lazy_list.m
	after polymorphism to fail.

compiler/*.m
	Fill in the args_method field of proc_infos with the value
	from the globals.
	Handle the extra argument to the lambda_goal unify_rhs.

compiler/follow_vars.m
	Remove code to handle complicated unifications, since
	they should be removed by polymorphism.m.

compiler/special_pred.m
library/mercury_builtin.m
	Make the uniqueness of the comparison_result argument
	of builtin_compare_* and the automatically generated
	comparison procedures match that of compare/3. Unique mode
	errors will still be introduced if polymorphism.m specializes
	calls to any of the unique modes of compare/3 and then mode analysis
	is rerun, since the compiler-generated comparison procedures
	only implement the (uo, in, in) mode. (This is not yet a problem
	because currently we don't rerun mode analysis.)

runtime/mercury_ho_call.c
	Remove code in do_call_*_closure to deal with the
	`simple' args_method. Since the output arguments no longer
	need to be moved, the closure call is now a tailcall.
	Remove some magic numbers.

compiler/modecheck_unify.m
	Avoid some aborts and mode errors when rerunning mode analysis,
	especially those resulting from not_reached insts being treated
	as bound.
	Avoid aborting on higher-order predicate constants with multiple
	modes if lambda expansion has already been run.

tests/valid/higher_order.m
        Add a test case for an abort in mode analysis when
	compiling with --deforestation (not yet committed),
	due to a predicate constant for a procedure with multiple
	modes.

tests/valid/unreachable_code.m
	Add a test case for bogus higher-order unification
	mode errors in unreachable code.
1998-02-12 01:17:56 +00:00
Zoltan Somogyi
5013dd9c76 Implement nondet pragma C codes.
Estimated hours taken: 40

Implement nondet pragma C codes.

runtime/mercury_stacks.h:
	Define a new macro, mkpragmaframe, for use in the implementation
	of nondet pragma C codes. This new macro includes space for a
	struct with a given sruct tag in the nondet stack frame being created.

compiler/{prog_data.m,hlds_goal.m}:
	Revise the representation of pragma C codes, both as the item and
	in the HLDS.

compiler/prog_io_pragma.m:
	Parse nondet pragma C declarations.

	Fix the indentation in some places.

compiler/llds.m:
	Include an extra argument in mkframe instructions. This extra argument
	gives the details of the C structure (if any) to be included in the
	nondet stack frame to be created.

	Generalize the LLDS representation of pragma C codes. Instead of a
	fixed sequence of <assign from inputs, user c code, assign to outputs>,
	let the sequence contain these elements, as well as arbitrary
	compiler-generated C code, in any order and possibly with repetitions.
	This flexibility is needed for nondet pragma C codes.

	Add a field to pragma C codes to say whether they can call Mercury.
	Some optimizations can do a better job if they know that a pragma C
	code cannot call Mercury.

	Add another field to pragma C codes to give the name of the label
	they refer to (if any). This is needed to prevent labelopt from
	incorrectly optimizing away the label definition.

	Add a new alternative to the type pragma_c_decl, to describe the
	declaration of the local variable that points to the save struct.

compiler/llds_out.m:
	Output mkframe instructions that specify a struct as invoking the new
	mkpragmaframe macro, and make sure that the struct is declared just
	before the procedure that uses it.

	Other minor changes to keep up with the changes to the representation
	of pragma C code in the LLDS, and to make the output look a bit nicer.

compiler/pragma_c_gen.m:
	Add code to generate code for nondet pragma C codes. Revise the utility
	predicates and their data structures a bit to make this possible.

compiler/code_gen.m:
	Add code for the necessary special handling of prologs and epilogs
	of procedures defined by nondet pragma C codes. The prologs need
	to be modified to include a programmer-defined C structure in the
	nondet stack frame and to communicate the location of this structure
	to the pragma C code, whereas the functionality of the epilog is
	taken care of by the pragma C code itself.

compiler/make_hlds.m:
	When creating a proc_info for a procedure defined by a pragma C code,
	we used to insert unifications between the headvars and the vars of
	the pragma C code into the body goal. We now perform substitutions
	instead. This removes a factor that would complicate the generation
	of code for nondet pragma C codes.

	Pass a moduleinfo down the procedures that warn about singletons
	(and other basic scope errors). When checking whether to warn about
	an argument of a pragma C code not being mentioned in the C code
	fragment, we need to know whether the argument is input or output,
	since input variables should appear in some code fragments in a
	nondet pragma C code and must not appear in others. The
	mode_is_{in,out}put checks need the moduleinfo.

	(We do not need to check for any variables being mentioned where
	they shouldn't be. The C compiler will fail in the presence of any
	errors of that type, and since those variables could be referred
	to via macros whose definitions we do not see, we couldn't implement
	a reliable test anyway.)

compiler/opt_util.m:
	Recognize that some sorts of pragma_c codes cannot affect the data
	structures that control backtracking. This allows peepholing to
	do a better job on code sequences produced for nondet pragma C codes.

	Recognize that the C code strings inside some pragma_c codes refer to
	other labels in the procedure. This prevents labelopt from incorrectly
	optimizing away these labels.

compiler/dupelim.m:
	If a label is referred to from within a C code string, then do not
	attempt to optimize it away.

compiler/det_analysis.m:
	Remove a now incorrect part of an error message.

compiler/*.m:
	Minor changes to conform to changes to the HLDS and LLDS data
	structures.
1998-01-13 10:14:23 +00:00
Zoltan Somogyi
bb4442ddc1 Update copyright dates for 1998.
Estimated hours taken: 0.5

compiler/*.m:
	Update copyright dates for 1998.
1998-01-13 10:06:08 +00:00
David Jeffery
7406335105 This change implements typeclasses. Included are the necessary changes to
Estimated hours taken: 500 or so

This change implements typeclasses. Included are the necessary changes to
the compiler, runtime and library.

compiler/typecheck.m:
	Typecheck the constraints on a pred by adding constraints for each
	call to a pred/func with constraints, and eliminating constraints
	by applying context reduction.

	While reducing the constraints, keep track of the proofs so that
	polymorphism can produce the tyepclass_infos for eliminated
	constraints.

compiler/polymorphism.m:
	Perform the source-to-source transformation which turns code with
	typeclass constraints into code without constraints, but with extra
	"typeclass_info", or "dictionary" parameters.

	Also, rather than always having a type_info directly for each type
	variable, sometimes the type_info is hidden inside a typeclass_info.

compiler/bytecode*.m:
	Insert some code to abort if bytecode generation is used when
	typeclasses are used.
compiler/call_gen.m:
	Generate code for a class_method_call, which forms the body of a class
	method (by selecting the appropriate proc from the typeclass_info).
compiler/dead_proc_elim.m:
	Don't eliminate class methods if they are potentially used outside
	the module
compiler/hlds_data.m:
	Define data types to store:
		- the typeclass definitions
		- the instances of a class
		- "constraint_proof". ie. the proofs of redundancy of a
		  constraint. This info is used by polymorphism to construct the
		  typeclass_infos for a constraint.
		- the "base_tyepclass_info_constant", which is analagous the
		  the base_type_info_constant
compiler/hlds_data.m:
	Define the class_method_call goal. This goal is inserted into the
	body of class method procs, and is responsible for selecting the
	appropriate part of the typeclass_info to call.
compiler/hlds_data.m:
	Add the class table and instance table to the module_info.
compiler/hlds_out.m:
	Output info about base_typeclass_infos and class_method_calls
compiler/hlds_pred.m:
	Change the representation of the locations of type_infos from "var"
	to type_info_locn, which is either a var, or part of a typeclass_info,
	since now the typeclass_infos contain the type_infos for the type that
	they constrain.

	Add constraints to the pred_info.

	Add constraint_proofs to the pred_info (so that typeclass.m can
	annotate the pred_info with the reasons that constraints were
	eliminated, so that polymorphism.m can in turn generate the
	typeclass_infos for the constraints).

	Add the "class_method" marker.

compiler/lambda.m:
	A feable attempt at adding class ontexts to lambda expressions,
	untested and almost certainly not working.
compiler/llds_out.m:
	Output the code addresses for do_*det_class_method, and output
	appropriately mangled symbol names for base_typeclass_infos.
compiler/make_hlds.m:
	Add constraints to the types on pred and func decls, and add
	class and instance declarations to the class_table and instance_table
	respectively.
compiler/mercury_compile.m:
	Add the check_typeclass pass.
compiler/mercury_to_mercury.m:
	Output constraints of pred and funcs, and output typeclass and instance
	declarations.
compiler/module_qual.m:
	Module qualify typeclass names in pred class contexts, and qualify the
	typeclass and instance decls themselves.
compiler/modules.m:
	Output typeclass declarations in the short interface too.
compiler/prog_data.m:
	Add the "typeclass" and "instance" items. Define the types to store
	information about the declarations, including class contexts on pred
	and func decls.
compiler/prog_io.m:
	Parse constraints on pred and func declarations.
compiler/prod_out.m:
	Output class contexts on pred and func decls.
compiler/type_util.m:
	Add preds to apply a substitution to a class_constraint, and to
	a list of class constraints. Add type_list_matches_exactly/2. Also
	add typeclass_info and base_typeclass_info as types which should not
	be optimised as no_tag types (seeing that we cheat a bit about their
	representation).
compiler/notes/compiler_design.html:
	Add notes on module qualification of class contexts. Needs expansion
	to include more stuff on typeclasses.
compiler/*.m:
	Various minor changes.

New Files:
compiler/base_typeclass_info.m:
	Produce one base_typeclass_info for each instance declaration.
compiler/prog_io_typeclass.m:
	Parse typeclass and instance declarations.
compiler/check_typeclass.m:
	Check the conformance of an instance declaration to the typeclass
	declaration, including building up a proof of how superclass
	constraints are satisfied so that polymorphism.m is able to construct
	the typeclass_info, including the superclass typeclass_infos.

library/mercury_builtin.m:
	Implement that base_typeclass_info and typeclass_info types, as
	well as the predicates type_info_from_typeclass_info/3 to extract
	a type_info from a typeclass_info, and superclass_from_typeclass_info/3
	for extracting superclasses.
library/ops.m:
	Add "typeclass" and "instance" as operators.
library/string.m:
	Add a (in, uo) mode for string__length/3.

runtime/mercury_ho_call.c:
	Implement do_call_*det_class_method, which are the pieces of code
	responsible for extracting the correct code address from the
	typeclass_info, setting up the arguments correctly, then executing
	the code.
runtime/mercury_type_info.h:
	Macros for accessing the typeclass_info structure.
1997-12-19 03:10:47 +00:00
Fergus Henderson
5976f769f7 Fix a bug for the case of a higher-order function call in code
Estimated hours taken: 1

Fix a bug for the case of a higher-order function call in code
with common sub-expression; mercury 0.7 failed this test, reporting
"Software Error: modecheck fails when repeated", due to confusion
between h.o. _function_ call and h.o. _predicate_ call.

compiler/hlds_goal.m:
	Add `pred_or_func' field to HLDS higher_order_calls.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/hlds_out.m:
compiler/*.m:
	Add code to handle new field for higher_order_call goals.

tests/valid/Mmake:
tests/valid/ho_func_call.m:
	Regression test for the above-mentioned bug.
1997-09-01 14:05:44 +00:00
Fergus Henderson
796f7f7436 Fix a bug which caused the code generator to fail on certain
Estimated hours taken: 16

Fix a bug which caused the code generator to fail on certain
examples involving predicates with determinism `erroneous'.

compiler/inst_match.m:
	Change `inst_is_bound' so that it succeeds for `not_reached' insts.
	This change is so that the behaviour of the predicate matches
	the documentation, and so that it is consistent with the behaviour
	of `inst_is_ground'.

compiler/liveness.m:
	When computing the value-giving occurrences, check explicitly
	for unreachable instmaps.  This is necessary to handle the above
	change to `inst_is_bound'.

	Fix a bug in detect_deadness: it was applying the deaths before
	the births, but it should be done in the other order.
	Normally deaths must be applied before births, but in detect_deadness
	we are traversing the goal backwards, so we must apply births first
	and then deaths.

	The old solution of just cancelling out any vars that occur in
	both the post-death and post-birth set was not quite right;
	instead we just need to apply them in the correct order.

compiler/code_info.m:
	Change the code so that it applies the pre/post deaths
	before applying the corresponding births.

compiler/live_vars.m:
compiler/store_alloc.m:
compiler/hlds_goal.m:
	Add some comments about making sure we always apply the deaths
	before applying the births.  (The code here was already correct,
	I just added some documentation.)

compiler/hlds_out.m:
	Print out the pre/post deaths before the pre/post births, so
	that the order that they are printed out in matches the order
	in which they should be applied.

tests/hard_coded/Mmake:
tests/hard_coded/erroneous_liveness.m:
tests/hard_coded/erroneous_liveness.exp:
tests/hard_coded/erroneous_liveness.inp:
	Regression test for the above-mentioned bug fix.
1997-08-23 20:35:08 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
Simon Taylor
27d156bbb5 Implemented a :- use_module directive. This is the same as
Estimated hours taken: 14

Implemented a :- use_module directive. This is the same as
:- import_module, except all uses of the imported items
must be explicitly module qualified.

:- use_module is implemented by ensuring that unqualified versions
of items only get added to the HLDS symbol tables if they were imported
using import_module.

Indirectly imported items (from `.int2' files) and items declared in `.opt'
files are treated as if they were imported with use_module, since all uses
of them should be module qualified.

compiler/module_qual.m
	Keep two sets of type, mode and inst ids, those which can
	be used without qualifiers and those which can't.

	Renamed some predicates which no longer have unique names since
	'__' became a synonym for ':'.

	Made mq_info_set_module_used check whether the current item is in
	the interface, rather than relying on its caller to do the check.

	Removed init_mq_info_module, since make_hlds.m now uses the
	mq_info built during the module qualification pass.

compiler/prog_data.m
	Added a pseudo-declaration `used', same as `imported' except uses of
	the following items must be module qualified.

	Added a type need_qualifier to describe whether uses of an item
	need to be module qualified.

compiler/make_hlds.m
	Keep with the import_status whether current item was imported
	using a :- use_module directive.

	Use the mq_info structure passed in instead of building a new one.

	Ensure unqualified versions of constructors only get added to the
	cons_table if they can be used without qualification.

compiler/hlds_module.m
	Added an extra argument to predicate_table_insert of type
	need_qualifier.

	Only add predicates to the name and name-arity indices if they
	can be used without qualifiers.

	Changed the structure of the module-name-arity index, so that
	lookups can be made without an arity, such as when type-checking
	module qualified higher-order predicate constants. This does not
	change the interface to the module_name_arity index.

	Factored out some common code in predicate_table_insert which
	applies to both predicates and functions.

compiler/hlds_pred.m
	Removed the opt_decl import_status. It isn't needed any more
	since all uses of items declared in .opt files must now be
	module qualified.

	Added some documentation about when the clauses_info is valid.

compiler/intermod.m
	Ensure that predicate and function calls in the `.opt' file are
	module qualified. Use use_module instead of import_module in
	`.opt' files.

compiler/modules.m
	Handle use_module directives.

	Report a warning if both use_module and import_module declarations
	exist for the same module.

compiler/mercury_compile.m
	Collect inter-module optimization information before module
	qualification, since it can't cause conflicts any more. This means
	that the mq_info structure built in module_qual.m can be reused in
	make_hlds.m, instead of building a new one.

compiler/prog_out.m
	Add a predicate prog_out__write_module_list, which was moved
	here from module_qual.m.

compiler/typecheck.m
	Removed code to check that predicates declared in `.opt' files
	were being used appropriately, since this is now handled by
	use_module.

compiler/*.m
	Added missing imports, mostly for prog_data and term.

NEWS
compiler/notes/todo.html
doc/reference_manual.texi
	Document `:- use_module'.

tests/valid/intermod_lambda_test.m
tests/valid/intermod_lambda_test2.m
tests/invalid/errors.m
tests/invalid/errors2.m
	Test cases.
1997-06-29 23:11:42 +00:00
Fergus Henderson
e3471f333f Fix a bug in inlining of polymorphic pragma c_code procedures.
Estimated hours taken: 3

Fix a bug in inlining of polymorphic pragma c_code procedures.

The bug was that if the actual argument type has a specific type
of say `float', then the C variable for the corresponding formal
parameter will be declared to have type `Float', whereas without
inlining the argument type would have been polymorphic and so
the C variable would have been declared to have type `Word'.
Hence we need to keep track of the original argument types,
before any inlining or specialization has occurred, and use
these original argument types to determine how to declare
the C variables, rather than using the actual argument types
for this particular specialization.

compiler/hlds_goal.m:
	Add a new field to pragma_c_code goals, holding the
	original argument types (before any inlining or specialization)
	of the pragma_c_code procedure.

compiler/make_hlds.m:
	Initialize this field with the declared argument types for
	the pragma c_code procedure.

compiler/polymorphism.m:
	Update this field to account for the inserted type_info variables.

compiler/code_gen.m:
	Pass this field to pragma_c_gen.m.

compiler/pragma_c_gen.m:
	Use the original argument types field for the pragma variable
	declarations, rather than looking up the actual types of the
	arguments.

compiler/*.m:
	Trivial changes to handle new field.

compiler/live_vars.m:
	Comment out some code to avoid a warning about `fail'
	in the condition of an if-then-else.
1997-05-05 11:17:40 +00:00
Zoltan Somogyi
4c3b0ecb09 Replace calls to map__set with calls to either map__det_insert or
Estimated hours taken: 3

Replace calls to map__set with calls to either map__det_insert or
map__det_update. In some cases this required a small amount of code
reorganization.
1997-04-07 05:39:59 +00:00
Fergus Henderson
3ec8a17ffc Enable the code to treat `__' as an alternative syntax for module
Estimated hours taken: 8

Enable the code to treat `__' as an alternative syntax for module
qualification, after fixing various places in the compiler where
we use `__' in ways that are incompatible with this.

compiler/prog_io.m:
compiler/prog_io_goal.m:
	Uncomment the code to handle `__' as module qualification.

compiler/intermod.m:
compiler/hlds_module.m:
compiler/modecheck_unify.m:
	Fix bugs in the handling of module qualified higher-order terms.

compiler/*.m:
	s/hlds__/hlds_/g

compiler/passes_aux.m:
	s/process__/process_/g

compiler/pragma_c_gen.m:
compiler/code_gen.m:
	s/code_gen__/pragma_c_gen__/ for the predicates defined in
	pragma_c_gen.m (this ought to have been done when the code
	was first moved from code_gen.m to pragma_c_gen.m).

compiler/llds.m:
	s/llds__proc_id/llds_proc_id/g
	The reason for this was to avoid ambiguity between proc_id
	in hlds_pred.m and llds__proc_id in llds.m.

compiler/quantification.m:
compiler/make_hlds.m:
compiler/mercury_to_c.m:
	s/goal_vars/quantification__goal_vars/g
	The reason for this was to avoid ambiguity between goal_vars
	in quantification.m and goal_util__goal_vars in goal_util.m.

compiler/dupelim.m:
compiler/optimize.m:
	s/dupelim__main/dupelim_main/g
	The reason for this change is that a program can only
	have one main/2 predicate.

compiler/prog_io_dcg.m:
	Remove the old "temporary hack" to strip off and ignore
	io__gc_call/1, since the new handling of `__' broke it.
	It was only useful for optimizing NU-Prolog performance,
	which we don't care about anymore.

compiler/mercury_compile.m:
compiler/modules.m:
compiler/intermod.m:
compiler/prog_io.m:
	Remove occurrences of io__gc_call.

compiler/llds_out.m:
compiler/base_type_info.m:
	Ensure that we properly handle the special hacks in mercury_builtin
	where predicates from other modules (e.g. term__context_init)
	are defined in mercury_builtin because they are needed for
	type_to_term and term_to_type.  llds_out.m: don't put
	`mercury_builtin' in the mangled names for those symbols.
	base_type_info.m: handle types whose status is "imported"
	in their own module.
1997-02-23 06:08:34 +00:00
Zoltan Somogyi
91c4330db7 The first half of a change to introduce nondet pragma C goals.
Estimated hours taken: 12

The first half of a change to introduce nondet pragma C goals.
This half makes the necessary modifications to the HLDS; the next
half will modify the LLDS and emit it.

prog_data:
	Add a new pragma type for nondet pragma c_codes; these specify
	the names of a a bunch of variables to save across backtracking,
	and a list of label names to which backtracking may take place.

	Rename is_recursive to may_call_mercury, since this is a more
	direct expression of the meaning.

prog_io:
	Move much of the functionality to new files.

prog_io_dcg, prog_io_goal, prog_io_pragma, prog_io_util:
	New files, made up of pieces of prog_io.

hlds_goal:
	Add an extra argument to the pragma_c_goals to store the extra
	information present in the new type of pragma c_codes.

det_analysis:
	Take into account that the new type of pragma_c goal may have
	more than one solution.

goal_util:
	Rename variables in the new field of pragma_cs.

live_vars:
	Allocate stack slots to the saved variables in the new type of pragma_c
	goals.

make_hlds:
	Handle the new type of pragma_c goals.

mercury_output, hlds_out:
	Output the new type of pragma_c goals.

garbage_out:
	Rename type "det" to "frame_type".

others:
	Ignore one more arg of pragma_c goals or import prog_io_util.
1997-01-27 07:45:40 +00:00
Zoltan Somogyi
54bb1c4a67 Move the code that generates code for pragma_c_codes to a new module.
Estimated hours taken: 3

code_gen, pragma_c_code:
	Move the code that generates code for pragma_c_codes to a new module.

llds:
	Change the representation of reg and temp lvals, in order to create
	the concept of a "register type" and to reduce memory requirements.

	Also add a comment indicating a possible future extension dealing with
	model_non pragma_c_codes.

code_exprn, code_info:
	Add the ability to request registers of a given type, or a specific
	register, when acquiring registers.

bytecode, bytecode_gen, call_gen, dupelim, exprn_aux, follow_vars, frameopt,
garbage_out, jumpopt, llds_out, middle_rec, opt_debug, opt_util, store_alloc,
string_switch, tag_switch, unify_gen, vn_block, vn_cost, vn_filter, vn_flush,
vn_order, vn_temploc, vn_type, vn_util, vn_verify:
	Small changes to accommodate the new register representation.

hlds_goal:
	Add a comment indicating a possible future extension dealing with
	model_non pragma_c_codes.

inlining:
	Add a comment indicating a how to deal with a possible future extension
	dealing with model_non pragma_c_codes.
1996-12-31 09:58:59 +00:00
Zoltan Somogyi
3243dbe238 The only significant change in this checkin is that liveness.m now
Estimated hours taken: 0.5

The only significant change in this checkin is that liveness.m now
tries to compute the best resume_locs for negations (it already did
for if-then-elses and disjunctions; leaving out negations was an
oversight in my earlier checkin).

The other changes are only syntactic:

I have removed the cont-lives and nondet-lives field from goal_info,
since they are not used anymore.

I have replaced the nondet-lives field in code_info, which is not used
anymore, with a follow-vars field, which is not used yet (but will be).

Some of the "read" access predicates in hlds_goal did not have "get" in
their name; I added them.
1996-12-18 11:09:52 +00:00
Zoltan Somogyi
08a5f48e2c Take the code generator a big step closer to notes/ALLOCATION.
Estimated hours taken: _____

Take the code generator a big step closer to notes/ALLOCATION.
The new code generator emits code that is smaller and faster than
the code we used to emit.

Nondet liveness is no longer used; nondet live sets are always empty.
In code that was being modified anyway, remove its handling. Other
uses will be removed later (this keeps this change from being far too big;
as it is it is merely too big). Similarly for cont-lives.

In several places, clarify the code that gathers several code pieces together.

call_gen:
	Unset the failure continuation and flush the resume vars to
	their stack slots before nondet calls.

	Move the code that decides whether a nondet call can be a tailcall
	to code_info.

code_aux:
	Remove the code to handle resume points, since these are now
	handled in the specific constructs that need them. Replace it
	with a sanity check.

code_exprn:
	Add a predicate to place multiple vars.

code_gen:
	Remove the predicate code_gen__generate_forced_goal, since it
	packaged together some operations that should be executed at different
	times.

	Don't unset the failure continuation after every nondet goal;
	this is now done in the constructs that need it.

	Modify the handling of negation to use resume point info
	according to notes/ALLOCATION.

	Remove the predicate code_gen__ensure_vars_are_saved which was
	use to save all lives variables to the stack before nondet
	disjunctions and if-then-elses; we don't do that anymore.

code_info:
	Significantly simplify and document the handling of failure
	continuations, and make the types involved abstract types.

	Factor out common code in the handling of det and semi commits.

	Keep track of "zombies", variables that are dead wrt forward
	execution but whose values we need because they may be needed
	at a resume point we can reach.

	Remove several now unneeded predicates, and introduce new
	predicates to help other modules.

code_util:
	Add a couple of predicates to check whether ia goal cannot fail before
	flushing all variables to the stack, and whether a goal cannot flush
	any variables to the stack. These are used in liveness to decide
	which entry labels will be needed at resume points.

disj_gen:
	Unify the handling of det and semi disjunctions. Model the code
	handling of nondet disjunctions on the code handling pruned
	disjunctions. It is possible that the handling of nondet and pruned
	disjunctions can also be unified; the new code should make this
	significantly easier.

	Make the code conform to notes/ALLOCATION. This means saving
	only the variables mentioned in the resume_point field, not
	flushing all live variables to the stack at the start of a
	nondet disjunction, handling zombies, and using the new method
	of flushing variables at the ends of branched structures.

ite_gen:
	Unify the handling of det and semi if-then-elses. Model the code
	handling of nondet if-then-elses on the code handling det/semi
	if-then-elses. It is possible that the handling of nondet and pruned
	if-then-elses can also be unified; the new code should make this
	significantly easier.

	Make the code conform to notes/ALLOCATION. This means saving
	only the variables mentioned in the resume_point field, not
	flushing all live variables to the stack at the start of a
	nondet if-then-else, handling zombies, and using the new method
	of flushing variables at the ends of branched structures.

	Apply the new rules about liveness in if-then-elses, which say that
	the else part is parallel not to the then part but to the conjunction
	of the condition and the then part.

dense_switch, lookup_switch, string_switch, switch_gen, tag_switch, middle_rec:
	Use the new method of flushing variables at the ends of branched
	structures. Don't call remake_with_store map; switch_gen will do so.

	Fix an old bug in lookup_switch.

	The code in switch_gen which looked for the special case of a two-way
	switch used to use a heuristic to decide which one was recursive and
	which one was a base case. We now check the codes of the cases.

hlds_goal:
	Adjust the structure of the resume_point field to make it easier
	to use. Add a more convenient access predicate.

hlds_out:
	Don't print the nondet liveness and cont live fields, since they are
	not used anymore. Comment out the printing of the context field,
	which is rarely useful. Modify the printing of the resume_point field
	to conform to its new definition.

live_vars:
	Use the resume_point field, not the nondetlives field, to decide
	which variables may be needed on backward execution. Remove some
	code copied from liveness.m.

liveness:
	Put the several pieces of information we thread through the traversal
	predicates into a single tuple.

	Don't put variables which are local to one branch of a branched
	structure into the post-birth sets of other branches.

	Apply the new rules about liveness in if-then-elses, which say that
	the else part is parallel not to the then part but to the conjunction
	of the condition and the then part. Variables that are needed in the
	else part but not in the condition or the then part now die in at the
	start of the condition (they will be protected by the resume point on
	the condition).

	We now treat pruned and non-pruned disjunctions the same way
	wrt deadness; the old way was too conservative (it had to be).

	We still mishandle branches which produce some variables but
	can't succeed.

mercury_compile:
	Liveness now prints its own progress message with -V; support this.

store_alloc:
	When figuring out what variables need to be saved across calls,
	make sure that we put in interference arcs between those variables
	and those that are required by enclosing resume points.

	Don't compute cont-lives, since they are not used anymore.

livemap:
	Fix the starting comment.
1996-12-18 08:56:10 +00:00
Zoltan Somogyi
ee24e66a71 Switch from using a stack of store_maps in the code_info to govern what
Estimated hours taken: 2.5

Switch from using a stack of store_maps in the code_info to govern what
goes where at the end of each branched structure to using the store map
fields of the goal expressions of those structures.

Fix variable names where they resembled the wrong kind of map(var, lval).

code_info:
	Remove the operations on stacks of store maps.
	Modify the generate_forced_saves and remake_with_store_map operations
	to take a store_map parameter.

	When making variables magically live, pick random unused variables
	to hold them, since we can no longer use the guidance of the top
	store map stack entry. This may lead to the generation of some
	excess move instructions at non-reachable points in the code;
	this will be fixed later.

code_gen:
	Remove the store map push and pop invocations.
	Modify the generate_forced_goal operation to take a store_map parameter.

code_exprn:
	Export a predicate for use by code_info.

middle_rec, disj_gen, ite_gen, switch_gen,
dense_switch, lookup_switch, string_switch, tag_switch:
	Pass the store map around to get it to invocations of the primitives
	in code_gen and code_info that now need it.

goal_util:
	Name apart the new follow_vars field in hlds__goal_infos.
	(This should have been in the change that introduced that field.)

common, constraint, cse_detection, det_analysis, dnf, excess, follow_code,
intermod, lambda, lco, liveness, make_hlds, mode_util, modes, polymorphism,
quantification, simplify, switch_detection, typecheck, unique_modes,
unused_args:
	Fix variable names.

follow_vars, store_alloc:
	Add comments.
1996-11-23 10:39:02 +00:00
Zoltan Somogyi
096e738e29 Ensure that the store maps at the ends of branched control structures
Estimated hours taken: 1

store_alloc:
	Ensure that the store maps at the ends of branched control structures
	contain entries for all live variables and no other variables, that
	every variable is mapped to a distinct location, and that these
	locations are real (not artificial locations employed as a convention).

liveness:
	(Rename and) export a predicate, to allow its duplicate in store_alloc
	to be removed.
1996-11-23 07:35:15 +00:00
Zoltan Somogyi
f8da25795a Documented the distinction between the three kinds of uses we have
Estimated hours taken: 3

hlds_goal:
	Documented the distinction between the three kinds of uses we have
	for map(var, lval): stack_slots, store_map and follow_vars.
	Added a new field, follow_vars, to hlds__goal_info.

follow_vars:
	Attach the follow_vars information to the kinds of goals listed
	in notes/ALLOCATION.

hlds_out:
	Print out the follow_vars field. Make some other outputs easier to
	read.

hlds_pred:
	Remove the follow_vars field of the proc_info, since the follow_vars
	of the goal_info of the goal of the procedure has taken its place.

code_gen:
	Use the follow_vars field from the main goal's goal_info, rather
	than the follow_vars field of the proc_info.

store_alloc:
	Attach the last follow_vars not to the proc_info but to the main goal.
1996-11-23 06:01:49 +00:00
Fergus Henderson
622b165a69 Fix some bugs with the handling of partially instantiated
Estimated hours taken: 16

Fix some bugs with the handling of partially instantiated
variables which have `no_tag' types.

N.B.  This fix does not handle the case of passing a partially
instantiated variable of a no_tag type to polymorphic predicate.
However, polymorphic predicates with partially instantiated
modes are a bit of a dodgy case anyway.

mode_util.m:
	Change mode_to_arg_mode to handle `no_tag' types properly.

unify_gen.m:
	Change the code to handle `no_tag' types properly.

arg_info.m, bytecode_gen.m:
	Pass the type of the variable, not just its mode,
	to mode_to_arg_mode, since whether a variable
	is `top_in' or not may depend on the type.

live_vars.m, liveness.m, store_alloc.m, unify_gen.m:
	Use `mode_to_arg_mode(..., top_in)' rather than
	`mode_is_input(...)', since here we're concerned
	with the low-level concept of top_in/top_out
	rather than the higher-level notion of input/output.

modecheck_unify.m:
	In split_complicated_subunifies, `mode_to_arg_mode(..., top_in)'
	rather than `mode_is_input(...)', for same reason as above.
	(In other parts of mode analysis we're concerned with the higher-level
	notion, but split_complicated_subunifies is basically just there
	for the code generator.)

type_util.m, make_tags.m, shapes.m:
	Put the test for a `no_tag' type into a utility predicate
	type_is_not_tag_type in type_util.m.

make_hlds.m:
	Change the code for add_builtin so that it puts the correct
	type annotations in the pred_info.  (The previous code was
	wrong, but the problem didn't show up until the new code in the
	other parts of this change tried to use the var_types field of
	the pred_info.)
1996-11-22 08:32:33 +00:00
Zoltan Somogyi
613f8c06d4 Replace the two delta_liveness fields of the goal_info with four
Estimated hours taken: 1.5

goal_util:
	Replace the two delta_liveness fields of the goal_info with four
	separate fields, {pre,post}{births,deaths}, since they were being
	used separate most of the time in any case. The new arrangement
	will require less storage.

other files:
	Use the interface predicates for getting at these sets separately.

There are no algorithmic changes in this checkin.
1996-11-22 01:56:32 +00:00
Andrew Bromage
06e05928e1 Makes instmap and instmap_delta into ADTs.
Estimated hours taken: 38

Makes instmap and instmap_delta into ADTs.

compiler/code_gen.m:
compiler/code_info.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/dnf.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/lookup_switch.m:
compiler/mode_debug.m:
compiler/mode_info.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/store_alloc.m:
compiler/switch_detection.m:
compiler/transform.m:
compiler/uniq_modes.m:
compiler/unused_args.m:
	Miscellaneous minor changes to use the new instmap.m

compiler/constraint.m:
	Removed unnecessary duplication of code in constraint__checkpoint/4
	and constraint__no_output_vars/2.

compiler/det_util.m:
	Changed no_output_vars/4 to det_no_output_vars/4, moved body
	of code to instmap.m.

compiler/instmap.m:
	Added abstract types instmap/0, instmap_delta/0.

	Added predicates:
		instmap__init_reachable/1, instmap__init_unreachable/1,
		instmap_delta_init_reachable/1,
		instmap_delta_init_unreachable/1, instmap__is_reachable/1,
		instmap__is_unreachable/1, instmap_delta_is_reachable/1,
		instmap_delta_is_unreachable/1, instmap__from_assoc_list/2,
		instmap_delta_from_assoc_list/2, instmap__vars/2,
		instmap__vars_list/2, instmap_delta_changed_vars/2,
		instmap_delta_lookup_var/3, instmap__set/3,
		instmap_delta_insert/4, instmap_delta_apply_instmap_delta/3,
		instmap_delta_restrict/3, instmap_delta_delete_vars/3,
		instmap__no_output_vars/4, instmap_delta_apply_sub/4,
		instmap__to_assoc_list/2, instmap_delta_to_assoc_list/2.

	Renamed predicates:
		instmap__lookup_var/3 (was instmap_lookup_var/3)
		instmap__lookup_vars/3 (was instmap_lookup_vars/3)
		instmap__apply_instmap_delta/3 (was apply_instmap_delta/3)
		instmap__merge/5 (was instmap_merge/5)
		instmap__restrict/3 (was instmap_restrict/3)

	Moved predicates:
		merge_instmap_delta/5 (from mode_util.m)

	Removed predicates:
		instmapping_lookup_var/3

compiler/mode_util.m:
	Moved merge_instmap_delta/5 to instmap.m
1996-11-19 01:18:24 +00:00
Zoltan Somogyi
24fdb52210 If the condition of an if-then-else contains only builtins,
Estimated hours taken: 0.5

live_vars:
	If the condition of an if-then-else contains only builtins,
	don't insist on the variables live on entry to the condition
	being allocated stack slots. This fixes the inefficiecy problem
	with int__abs noticed by Fergus.

hlds_out:
	For internal and/or inline calls, print out that fact with -V.

store_alloc:
	Remove an unintended comment.
1996-11-08 10:58:46 +00:00
Zoltan Somogyi
cdc1c3872c Fix singleton-variable warning in my last commit.
Estimated hours taken: 0.01

Fix singleton-variable warning in my last commit.
1996-11-08 09:41:16 +00:00
Zoltan Somogyi
6af61e59dd If X is assigned to Y, treat it as a hint that the preferred location
Estimated hours taken: 1

follow_vars:
	If X is assigned to Y, treat it as a hint that the preferred location
	for X is the same as the preferred location for Y.

store_alloc:
	In the store maps at the ends of branched control structures,
	don't allocate storage to variables that aren't live at that point.
1996-11-08 09:06:14 +00:00
Zoltan Somogyi
5d64b759db The main changes are
Estimated hours taken: 12

The main changes are

1	associating a name with the arguments of constructors

2	removing the follow_vars field from calls, higher-order calls
	and complicated unifications, since they are not used

3	merging the follow_vars and store_alloc passes, since they logically
	belong together

4	add a new module, lco, for detecting opportunities for last
	call optimization modulo constructor application; it won't
	actually apply the optimization until the mode system becomes
	expressive enough to handle it (this module detects 529 opportunities
	in the compiler and library)

5	make "-O3 --optimize-value-number" do the right thing; previously,
	it used not to apply value numbering because the vnrepeat option
	defaulted to zero

6	don't refer to .err2 files anymore; use .err instead.

prog_data:
	The list associated with each value of type "constructor" now
	contains not only the types of the arguments but their names as well.

equiv_type, hlds_data, hlds_out, make_hlds, mercury_to_{goedel,mercury},
mode_util, module_qual, shapes, type_util, unify_proc:
	Modify the traversal of type definitions to account for the names
	in the lists inside values of type "constructor".

prog_io:
	Parse argument names. An unrelated change is that we now
	check whether :- pred declarations give modes to some of their
	arguments but not to all, in which case we return an error.

hlds_goal:
	Remove the follow_vars field from calls, higher-order calls
	and complicated unifications.

*.m:
	Handle the new arities of calls, higher order calls and complicated
	unifications.

mercury_compile:
	Don't call follow_vars directly anymore, but do call lco if its option
	is set. Also flush the main output before a call to maybe_report_stats
	to prevent ugly output.

store_alloc:
	Call follow_vars directly.

follow_vars:
	Expose the initialization and traversal predicates for store_alloc.

lco:
	Find opportunities for last call optimization modulo constructor
	application.

passes_aux:
	Add a HLDS traversal type for lco.

optimize:
	Consider the vnrepeat count to be zero unless value numbering is on.

options:
	Set the default value of vnrepeat to 1.

modules:
	Don't refer to .err2 files.
1996-11-04 06:26:51 +00:00
Fergus Henderson
5fe0f4f82c A bunch of changes required to fix problems in code generation for
Estimated hours taken: 24

A bunch of changes required to fix problems in code generation for
model_det and model_semi disjunctions.

simplify.m:
	Don't convert all model_det and model_semi disjunctions into
	if-then-elses, because that doesn't work if the disjuncts
	have output variables, which can happen (e.g. with cc_nondet
	disjunctions)

disj_gen.m:
	Fix a bug in the code generation for semidet disjunctions:
	don't forget to jump to the end of the disjunction after
	each disjunct!

liveness.m, live_vars.m, store_alloc.m, disj_gen.m:
	Treat backtracking in model_det and model_semi disjunctions
	as shallow backtracking rather than deep backtracking.
	This means that rather than pushing all live variables
	onto the stack at the start of a model_det/semi disjunction,
	and using the nondet_lives to keep track of them, we instead
	treat these disjunctions a bit more like an if-then-else and
	use the ordinary liveness/deadness to keep track of them.

code_aux.m:
	Change code_aux__pre_goal_update so that it only applies
	the post-deaths if the goal is atomic.  Applying the
	*post*-deaths to the set of live variables in the *pre*-goal
	update only makes sense for atomic goals.
	(I think previously we only ever generated post-deaths
	for atomic goals, but now we generate them also for
	goals inside model_det or model_semi disjunctions.)

code_gen.pp, middle_rec.m:
	Pass an is-atomic flag to code_aux__pre_goal_update.

hlds_goal.m:
	Add some comments.

goal_util.m:
	Fix bugs in goal_util__name_apart_goalinfo.
	It wasn't applying the substitution to all the
	appropriate fields.

code_exprn.m:
	Improve the error message for one of the internal errors.

hlds_out.m:
	Print the stack slot allocations in the HLDS dump again.
1996-10-29 20:10:17 +00:00
Andrew Bromage
5c149e55b2 Mode analyser reorganisation.
Estimated hours taken: 20

Mode analyser reorganisation.

compiler/mode_util.m:
	Removed: instmap_init/1,  apply_instmap_delta/3, instmap_lookup_var/3,
	instmapping_lookup_var/3, instmap_restrict/3, map_restrict/3 (all
	moved to instmap.m).

compiler/hlds_goal.m:
	Removed the declarations of instmap_delta, instmap and instmapping.

compiler/mode_errors.m:
	Added report_mode_errors/2 (was modecheck_report_errors, from
	modes.m).

compiler/modes.m:
	Predicates now exported:
		modecheck_goal/4
		modecheck_goal_expr/5 (previously named modecheck_goal_2/5)
		handle_extra_goals/8
		mode_context_to_unify_context/3

	Moved to mode_errors.m:
		modecheck_report_errors/2

	Moved to instmap.m:
		compute_instmap_delta/4
		instmap_merge/3
		instmap_lookup_vars (was instmap_lookup_arg_list/3)
		compute_instmap_delta/4

	Moved to mode_debug.m:
		Type port/0
		mode_checkpoint/4

	Moved to modecheck_call.m:
		modecheck_call_pred/7
		modecheck_higher_order_call/10
		modecheck_higher_order_pred_call/4
		modecheck_higher_order_func_call/7

	Moved to modecheck_unify.m:
		modecheck_unification/9
		categorize_unify_var_var/12
		categorize_unify_var_functor/11
		categorize_unify_var_lambda/9

	Moved to mode_info.m:
		mode_info_error/4
		mode_info_add_error/3

compiler/code_gen.pp, compiler/code_info.m, compiler/constraint.m,
compiler/cse_detection.m, compiler/det_analysis.m, compiler/det_util.m,
compiler/dnf.m, compiler/goal_util.m, compiler/higher_order.m,
compiler/hlds_out.m, compiler/hlds_pred.m, compiler/live_vars.m,
compiler/liveness.m, compiler/lookup_switch.m, compiler/polymorphism.m,
compiler/simplify.m, compiler/store_alloc.m, compiler/switch_detection.m,
compiler/transform.m, compiler/unused_args.m:
	Imported instmap.m

New files:

compiler/instmap.m:
	Handle operations associated with instmaps.

compiler/modecheck_unify.m:
	Handle mode checking of unifications.

compiler/modecheck_call.m:
	Handle mode checking of calls

compiler/mode_debug.m:
        Code to trace the actions of the mode checker.
1996-10-17 05:28:01 +00:00
Zoltan Somogyi
a15c032df7 Flesh out the code already here for traversing module_infos,
Estimated hours taken: 4

passes_aux:
	Flesh out the code already here for traversing module_infos,
	making it suitable to handle all the passes of the back end.

mercury_compile:
	Use the traversal code in passes_aux to invoke the back end passes
	over each procvedure in turn. Print a one-line message for each
	predicate if -v is given (this fixes a long-standing bug).

excess.m, follow_code.m, follow_vars.m, live_vars.m, lveness.m, store_alloc.m:
	Remove the code to traverse module_infos, since it is now unnecessary.

export.m:
	Remove an unused argument from export__produce_header_file_2.

others:
	Move imports from interfaces to implementations, or in some cases
	remove them altogether.
1996-08-03 12:06:26 +00:00
Fergus Henderson
0e1e0b0b91 Implement recursive' and non_recursive' pragma c_code declarations.
Estimated hours taken: 4

Implement `recursive' and `non_recursive' pragma c_code declarations.
This allows the compiler to optimize cases when the C code
is known to not call Mercury code.  It's also necessary
to allow C code which modifies the hp register to work
(such code must be declared `non_recursive', otherwise
the registers will be saved and restored over it).
To make things bootstrap OK, the old pragma c_code declarations
default to `non_recursive'.

prog_data.m, hlds_goal.m:
	Add new field c_is_recursive to pragma c_code goals.

prog_io.m:
	Parse the new `recursive' and `non_recursive' pragma c_code
	declarations.

make_hlds.m:
	Pass the c_is_recursive field from the parse tree to the HLDS.

live_vars.m:
	For non-recursive C code, don't save variables on the stack.

code_gen.pp:
	For non-recursive C code, don't save variables on the stack,
	don't mark the succip as needing to be saved, and don't
	call save_registers() and restore_registers().

*.m:
	Change c_code/5 to c_code/6.
1996-06-10 17:18:50 +00:00
Thomas Conway
af15674b0e set union and intersection are more efficient in some
Estimated hours taken: 0.2

set union and intersection are more efficient in some
implementations if you give the arguments in a particular order.
Our convention is big set first, small set second. These
changes just swap the order of the arguments in a few places.

compiler/modes.m,store_alloc.m:
	change the order of the arguments in a couple of calls
	to set__intersect and set__union.
1996-05-18 04:52:45 +00:00
Zoltan Somogyi
140ff7c9ff These now compile without errors. No other promises are made :-)
Estimated hours taken: 5

bytecode*.m:
	These now compile without errors. No other promises are made :-)

options:
	Adda new option, --generate-bytecode.

mercury_compile:
	Generate bytecode if the option is set.

goal_util:
	Add a predicate to find all the variables in a goal, even the ones
	that have been quantified. Used by the bytecode generator.

call_gen:
	Add a predicate and export another for use by the bytecode generator.

hlds_module:
	Add a predicate to look up full naming details on a PredId.
	Used by the bytecode generator.

hlds_pred:
	Remove the follow_vars field from proc_infos, since it is not needed
	any more.

hlds_goal:
	Remove the store_map field from goal_infos, since it is not needed
	any more.

code_gen, code_info, follow_vars, goal_util, hlds_out, middle_rec, store_alloc:
	Accommodate the changes in hlds_goal and hlds_pred

vn_block:
	Fix an oversight in my previous change.
1996-05-14 02:56:50 +00:00
Zoltan Somogyi
89644bebb2 Fixed a bug that caused restores of succip to be put in the wrong
Estimated hours taken: 5

peephole:
	Fixed a bug that caused restores of succip to be put in the wrong
	place, but only after predicate-wide value numbering.

opt_debug:
	Added a couple of debugging predicates used in tracking down this bug.

value_number:
	Fix a bug that left a livevals pseudo-op in the wrong place if a
	single instruction sequence contained more than one such pseudo-op.

options:
	Add --debug-opt. Rename --vndebug to --debug-vn.
	Add --generate-bytecode.

optimize, vn_debug:
	Use the new routines in opt_debug, and use the new/renamed options.

store_alloc:
	Don't thread follow_vars through the module, since the follow_vars
	information is not attached directly to branched structures. We
	now also use the same slot to hold the store map computed by this
	pass; this should allow the later deletion of the store map slot
	from goal_infos.

follow_code:
	Removed dead predicate.

livemap:
	Added a comment.
1996-05-12 04:51:14 +00:00