Commit Graph

2202 Commits

Author SHA1 Message Date
Zoltan Somogyi
09141817ba 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:29:17 +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
David Jeffery
1b0472461c Disable the often erroneous "optimisation" in check_typeclass.m whereby we
Estimated hours taken: 3

Disable the often erroneous "optimisation" in check_typeclass.m whereby we
skipped the level of indirection for instance methods if there was an exact
match for the types, modes and determinisms of the instance method.
Consequently rip out lots of useless stuff from check_typeclass.m.

Also, for methods which are functions, introduce unifications for the body
rather than calls.

Also improve a couple of error messages slightly.

compiler/check_typeclass.m:
        Disable the "optimisation".
1998-06-08 07:46:59 +00:00
Fergus Henderson
151b4e9176 Fix an error in my previous change that I accidentally
Estimated hours taken: 0.5

compiler/mercury_compile.m:
	Fix an error in my previous change that I accidentally
	introduced while merging in stayl's changes.
1998-06-05 09:12:07 +00:00
Fergus Henderson
fdc28ddd56 Improve the modularity of the code in purity.m by splitting it into two
Estimated hours taken: 2

Improve the modularity of the code in purity.m by splitting it into two
modules and fix a purity-related bug by moving some code from typecheck.m
into the new module.

compiler/post_typecheck.m:
	New module.  Handles the typechecking stuff that happens
	after typecheck.m.

compiler/purity.m:
	Move the typechecking related code in purity.m into post_typecheck.m.

compiler/typecheck.m:
	Move the code for copying clauses to the proc_infos, etc. into
	new predicates in post_typecheck.m.  This code is now called
	from purity.m rather than from typecheck.m.
	(I think the fact that it was being done in typecheck.m was a
	bug -- it meant that the goal_info flags computed by purity.m
	were not being copied across to the proc_infos.)

compiler/mercury_compile.m:
compiler/typecheck.m:
	Don't pass the ModeError parameter down to typecheck_pred,
	since with the above change it isn't needed anymore.

compiler/mercury_compile.m:
	Run purity checking before writing the `.opt' files.
	This is necessary because writing out the `.opt' files
	requires that code in post_typecheck__finish_pred
	(formerly in typecheck.m) has been run.

compiler/notes/compiler_design.html:
	Document these changes.
1998-06-04 17:26:23 +00:00
Simon Taylor
98c2fbf51b Bug fixes.
Estimated hours taken: 12

Bug fixes.

tests/term/arit_exp.m still fails with --intermodule-optimization
due to a slightly different (but correct) trans_opt file being produced.

compiler/simplify.m
	Don't produce singleton disjunctions, since the code generator
	barfs on them. Use a `some' instead.
	Test case: tests/general/partition.m compiled with --deforestation.

compiler/unused_args.m
	Deconstructions where the arguments included `any' insts were
	not being handled correctly, due to inst_matches_binding
	failing for any->any.
	Test case: extras/trailed_update/samples/vqueens.m at -O3.
	Don't warn about predicates from `.opt' files having unused
	arguments, because in most cases the warning will be generated
	when compiling the imported module.

compiler/higher_order.m
	Fix a bug that caused compiler/modules.m to be miscompiled at
	-O3 --intermodule-optimization, due to curried arguments for
	multiple known higher-order arguments being passed to a
	specialised version in the wrong order.
	Test case: tests/hard_coded/ho_order2.m

compiler/mercury_compile.m
	Call intermod__update_pred_import_status when compiling to
	C at the same stage of the compilation as the `.opt' file
	was written to ensure that the same information is being used.
	Test case: tests/hard_coded/rational_test.m compiled with
	--intermodule-optimization failed because of a link error.
	Make sure polymorphism has been run before doing unused argument
	checking with --errorcheck-only. Otherwise the argument indices
	read in from `.opt' files are incorrect.

compiler/intermod.m
	Use code_util__compiler_generated to test if a called predicate
	is compiler generated, rather than looking for a call_unify_context
	(function calls have a call_unify_context).
	Add a progress message for updating the import status of predicates
	exported to `.opt' files.
	Fix a bug where the unused_args pragmas read in from the current
	module's `.opt' file were given an import_status of `imported' rather
	than `opt_imported' resulting in an error message from make_hlds.m.

compiler/dead_proc_elim.m
	Ensure that predicates used by instance declarations and
	`:- pragma export's are not eliminated by the dead_pred_elim
	pass before typechecking.
	Test case: most of the typeclass tests compiled with
	--intermodule-optimization.

compiler/hlds_goal.m
	Remove obsolete comments about the modes of a higher-order
	unification being incorrect after polymorphism, since that
	was fixed months ago.

compiler/options.m
	Reenable deforestation.
	Enable --intermodule-optimization and --intermod-unused-args
	at -O5 so they get tested occasionally.

compiler/handle_options.m
	Disable deforestation if --typeinfo-liveness is set, since
	there are bugs in the folding code if extra typeinfos are
	added to a new predicate's arguments by hlds_pred__define_new_pred.
	Disable higher_order.m if --typeinfo-liveness is set, since
	higher_order.m currently does not pass all necessary typeinfos
	to specialised versions or update the typeinfo_varmap of
	specialised versions.
	Test case: tests/valid/agc_ho_pred.m

tests/hard_coded/ho_order2.m
tests/hard_coded/ho_order2.exp
	Test case for higher_order.m.

tools/test_mercury
	Added --intermod-unused-args to the options for murlibobo.

extras/trailed_update/{samples,tests}/Mmakefile
	Add "-I.." to MGNUCFLAGS so gcc can find unsafe.h which
	is #included in c_header_code read from unsafe.opt.
1998-06-03 00:44:04 +00:00
Fergus Henderson
7370e9117d Fix some bugs in code generation for nondet disjunctions and
Estimated hours taken: 4.5

Fix some bugs in code generation for nondet disjunctions and
if-then-elses.  The compiler was incorrectly releasing the temp stack
slots used to save the heap pointer and trail pointer at the start
of the else or the last clauses, thus allowing them to be reused not
only in the else case or the last clause, but also by goals following the
disjunction or if-then-else, even though the values in these slots might
be needed again on backtracking into the condition or the earlier
disjunctions.

Thanks to Warwick Harvey for reporting this bug.

compiler/code_info.m:
	Add new predicate `code_info__maybe_reset_and_pop_ticket',
	which is like `code_info__maybe_reset_and_discard_ticket',
	except that it does not release the temp stack slot.

compiler/disj_gen.m:
compiler/ite_gen.m:
	When generating code for nondet goals that save
	and restore the hp and trail, if the saved
	values might be needed again on backtracking
	into the current goal from one that follows
	(i.e. in nondet disjunctions and in if-then-elses
	with nondet conditions), make sure we use
	`code_info__maybe_reset_and_pop_ticket' and
	`code_info__reset_hp' instead of
	`code_info__maybe_reset_and_discard_ticket' and
	`code_info__reset_and_discard_hp'.

compiler/code_info.m:
	Include the temp_avail_slots in the set of things
	that slap_code_info does not update.  Temp slots
	that were acquired (and not released) in one branch
	of a branched goal need to be still reserved at the
	end of the branched goal.

extras/trailed_update/Mmakefile:
extras/trailed_update/samples/Mmakefile:
extras/trailed_update/samples/tests.m:
extras/trailed_update/samples/tests.exp:
extras/trailed_update/tests/Mmakefile:
extras/trailed_update/tests/var_test.m:
extras/trailed_update/tests/var_test.exp:
	Add a new subdirectory `tests' in extras/trailed_update,
	and move the test case `tests.{m,exp}' from the samples
	subdirectory into the tests subdirectory, at the same
	time renaming it as `var_test.{m,exp}'.

extras/trailed_update/tests/Mmakefile:
extras/trailed_update/tests/func_trail_test.m:
extras/trailed_update/tests/func_trail_test.exp:
extras/trailed_update/tests/func_trail_test_2.m:
extras/trailed_update/tests/func_trail_test_2.exp:
	Add a couple of regression tests for the bug mentioned above.
	These tests need to go here rather than somewhere in the
	main `tests' directory (e.g. `tests/hard_coded'), because
	they only work in trailing grades, and the normal tests are
	compiled in lots of grades, many of which don't have
	corresponding trailing grades installed.
	(I suppose we could put them in the main `tests' directory,
	and only enable them for trailing grades, but it just seemed
	easier to put them here.)
1998-06-02 05:32:26 +00:00
Fergus Henderson
f20cd077ad Update some obsolete documentation.
Estimated hours taken: 0.1

compiler/unique_modes.m:
	Update some obsolete documentation.
1998-06-01 00:22:25 +00:00
Fergus Henderson
731ae2051f Allow a predicate to have matching cc' and non-cc' modes.
Estimated hours taken: 3

Allow a predicate to have matching `cc' and `non-cc' modes.

compiler/det_analysis.m:
	If there is a call to a cc procedure in a non-cc context,
	then search for a mode of that predicate which is
	identical to the called mode except that it is not cc.
	If such a mode is found, use it, rather than reporting
	an error.

compiler/modecheck_call.m:
	Add predicate modes_are_identical_bar_cc, for use by
	det_analysis.m.

NEWS:
LIMITATIONS:
doc/reference_manual.texi:
	Document the new feature and delete documentation about the
	lack of this feature.

tests/hard_coded/Mmakefile:
tests/hard_coded/cc_and_non_cc_test.m:
tests/hard_coded/cc_and_non_cc_test.exp:
	Add a test case for the new feature.
1998-05-30 15:23:14 +00:00
Fergus Henderson
38ae5fe0c5 Fix a bug which caused link errors in some grades for some test cases
Estimated hours taken: 1

Fix a bug which caused link errors in some grades for some test cases
where the module name wasn't the same as the file name, and which
probably would have caused runtime errors in some grades for test
cases using nested modules.

compiler/modules.m:
	Call $(C2INIT) with $(foo.cs) instead of $(foo.ms).
	This is necessary now that a single .m file can get compiled
	to multiple .c files, if it contains nested modules,
	or to a .c file whose name reflects the module name rather
	than the source file name.

util/mkinit.c:
scripts/c2init.in:
	For efficiency, change c2init and mkinit so that when c2init's
	arguments are `.c' files, it computes the init function based
	on the filename (like it used to do with `.m' files), rather
	than by reading the file contents and searching for "** INIT"
	comments.  Add a new option `-x' (`--extra-inits') which keeps
	the old behaviour.

compiler/modules.m:
scripts/Mmake.rules:
	Instead of deleting the `_init.c' file every time we recreate
	the `.dep' file, just tell make that the `_init.c' file depends on
	the `.dep' file, so that make will remake it if the `.dep' file
	changes.  (I don't know why I didn't do it that way in the
	first place.)
1998-05-30 13:34:17 +00:00
Fergus Henderson
19ed0e5a32 Avoid spurious warning messages about source file
Estimated hours taken: 0.1

compiler/prog_io.m:
	Avoid spurious warning messages about source file
	`bar.m' containing module `foo:bar' -- this case
	is supported, and should not trigger a warning.
1998-05-30 12:25:45 +00:00
Fergus Henderson
7ccca98b18 Put library files and `.init' files in the current directory,
Estimated hours taken: 1

compiler/modules.m:
	Put library files and `.init' files in the current directory,
	rather than in Mercury/libs and Mercury/inits subdirectories,
	even if `--use-subdirs' is enabled.
	Without this change, the instructions on "Using libraries"
	in the Mercury user's guide did not work in conjunction with
	`--use-subdirs', and they, as well as a lot of Mmakefiles that
	were defined based on them, would need to be changed.
1998-05-30 07:38:12 +00:00
Fergus Henderson
e880e3ac59 Allow modules to be put in source files whose names do not directly match
Estimated hours taken: 12

Allow modules to be put in source files whose names do not directly match
their the module names.  When looking for the source for a module such
as `foo:bar:baz', search for it first in `foo.bar.baz.m', then in `bar.baz.m',
and finally in `baz.m'.

compiler/prog_io.m:
	Change prog_io__read_module so that it returns the name of
	the module read, as determined by the `:- module' declaration.
	Add predicate `check_module_has_expected_name', for checking
	that this name matches what was expected.

compiler/modules.m:
	Add read_mod_from_file, for reading a module given the file name,
	and generated_file_dependencies, for generating the dependencies
	of a module given the file name.  (As opposed to the module name.)
	Change read_mod and read_mod_ignore_errors so that they
	search for `.m' files as described above, and return the name
	of the source file read.
	Also improve the efficiency of read_dependencies slightly:
	when reading in `.int' files, there's no need to call
	split_into_submodules, because we generate a seperate
	`.int' file for each submodule anyway.

compiler/mercury_compile.m:
	Change the handling of command-line arguments.
	Arguments ending with `.m' are assumed to be file names,
	and other arguments are assumed to be module names.
	For file names, call read_mod_from_file instead of read_mod.

compiler/handle_options.m:
	Change help message to reflect the above change to the semantics
	of command-line arguments.

compiler/intermod.m:
compiler/trans_opt.m:
	Fix a bug: call prog_io__read_opt_file instead of prog_io__read_module.

doc/user_guide.texi:
	Document the above change to the semantics of command-line arguments.
	Update the "libraries" chapter to reflect our support for nested
	modules.

tests/*/*.m:
tests/*/*.exp:
	Fix a few incorrect module names in `:- module' declarations.
1998-05-29 08:50:57 +00:00
David Jeffery
d206d5a3e7 Fix a bug where variable names were getting mixed up for certain introduced
Estimated hours taken: 15

Fix a bug where variable names were getting mixed up for certain introduced
instance method predicates.

compiler/check_typeclass.m:
	Calculate the variables names correctly (ie. get the renaming
	right).
compiler/typecheck.m:
	Make typecheck_info_get_final_info also rename the declared
	constraints for the predicate. After getting the final info, store
	the new versions of the arg types and the renamed constraints,
	regardless of whether we are doing type inference or not.

	Although the intention was originally that the var numbers would
	only be changed in typecheck_info_get_final_info when doing
	inference (since that is the only time that redundant type vars
	would be present), this is no longer the case. Preds introduced in
	typecheck.m can also have redundant type vars in the varset at the
	time of creation since they have the *class declarations's* tvarset.
	This meant that typecheck_info_get_final_info was getting rid of
	some variables, then updating the proofs, but not updating the
	constraints, arg types etc.
1998-05-27 14:36:55 +00:00
Fergus Henderson
935fbfe36e Add Mmake support for nested sub-modules.
Estimated hours taken: 6

Add Mmake support for nested sub-modules.

compiler/mercury_compile.m:
compiler/modules.m:
compiler/intermod.m:
	Pass down the source file name to various places.
	Store the source file name in the module_imports data structure.
	In various places, use this source file name instead of assuming
	that the source file name can be obtained from the module name.

compiler/modules.m:
	Change the generated .d and .dep files to use the source file names.
	Add hard-coded rules in the .d files if the source file name does not
	match the form expected by the pattern rules in scripts/Mmake.rules.
	XXX unfortunately the rules don't work right for parallel makes of
	    nested modules

scripts/Mmake.rules:
	Add a comment saying that any changes here might need to
	be duplicated in compiler/modules.m.

tests/hard_coded/Mmakefile:
tests/hard_coded/nested.m:
tests/hard_coded/nested2.m:
tests/hard_coded/nested.exp:
tests/hard_coded/nested2.exp:
	Add a couple of test cases for nested modules (XXX not enabled,
	due to the above-mentioned problem with parallel makes).

doc/reference_manual.texi:
	Update the "implementation bugs and limitations" section.

NEWS:
	Update the news about nested modules.
1998-05-27 04:00:54 +00:00
Fergus Henderson
300fdfcada Fix a warning about `list' being imported in the interface
Estimated hours taken: 0.1

compiler/export.m:
	Fix a warning about `list' being imported in the interface
	section but only used in the implementation section.
1998-05-27 02:20:11 +00:00
Fergus Henderson
b9d40ad759 Fix a bug where --generate-dependencies was writing out
Estimated hours taken: 2

compiler/modules.m:
	Fix a bug where --generate-dependencies was writing out
	an overly conservative set of dependencies.
1998-05-26 20:49:24 +00:00
Fergus Henderson
6f963f604e More improvements to the compiler support for nested sub-modules.
Estimated hours taken: 0.5

More improvements to the compiler support for nested sub-modules.

compiler/mercury_compile.m:
	Handle linking of modules containing nested sub-modules properly,
	i.e. link in the object files for the sub-modules too.
1998-05-26 20:31:19 +00:00
Fergus Henderson
9e02faf9c4 Implement compiler support for nested sub-modules.
Estimated hours taken: 5

Implement compiler support for nested sub-modules.
(Mmake support is still missing, so you have to compile by hand.
Also you must use `ml' to link rather `mmc', because
`mmc' doesn't link all the object files that it generates.)

compiler/prog_io.m:
	Fix a couple of bugs in the parsing of `module' and `end_module'
	declarations.

compiler/mercury_to_mercury.m:
	Handle output of `:- module' and `:- end_module' declarations.

compiler/modules.m:
	Add predicate split_into_submodules, which takes the item_list
	for a module and splits it into a list of item_lists for each
	submodule.

compiler/mercury_compile.m:
	Change the code for creating interface files and generating
	LLDS fragments so that it calls split_into_submodules and then
	iterates over each submodule.

That means that we now generate a seperate HLDS for each submodule, and
compile that to a seperate LLDS and a seperate C file.  It would be
more efficient to combine the LLDS fragments for each submodule after
code generation, generate a single C file, and thus only invoke the C
compiler once.  In view of this goal, I have done some cleaning up of
the HLDS/LLDS distinction, so that we don't need to pass the HLDS to
the various LLDS output routines.  (However, I haven't actually gotten
as far as combining the LLDS code fragments.)

compiler/llds.m:
	Add type `c_interface_info' which contains information from the
	HLDS that is used during the LLDS output pass.

compiler/mercury_compile.m:
	Add a predicate `get_c_interface_info' which gets the relevant
	info from the HLDS that is needed for LLDS output.

compiler/export.m:
	Add `export__get_c_export_decls', and rename
	`export__get_pragma_exported_procs' as `export__get_c_export_defns'.
	Change export__produce_header_file so that it takes a `c_export_decls'
	(part of the `c_interface_info') instead of an HLDS.
1998-05-26 19:19:22 +00:00
Fergus Henderson
247b1c24b9 Fix various invasions of the user's namespace by `mercury_builtin.m',
Estimated hours taken: 6

Fix various invasions of the user's namespace by `mercury_builtin.m',
by splitting mercury_builtin.m into two modules, called builtin.m and
private_builtin.m, and ensuring that the latter is imported as if
by `:- use_module' rather than `:- import_module'.

library/builtin.m:
library/private_builtin.m:
	Split mercury_builtin.m into two modules, builtin.m,
	which contains stuff intended to be public,
	and private_builtin.m, which contains implementation
	details that are not supposed to be public.

library/mercury_builtin.m:
	Add a comment saying that this module is no longer used, and
	should eventually be removed.  I have not removed it yet, since
	that would prevent bootstrapping with the current compiler.  It
	will be removed as a seperate change later, once all the
	changes have propagated.

compiler/prog_util.m:
	Change the definition of mercury_private_builtin_module/1 and
	mercury_public_builtin_module so that instead of automatically
	importing mercury_builtin.m as if by `import_module', the
	copiler will now automatically import builtin.m as if by
	`import_module' and private_builtin.m as if by `use_module'.

compiler/polymorphism.m:
	Change a call to mercury_private_builtin_module/1 for
	unsafe_promise_unique to instead call mercury_public_builtin_module/1.

compiler/unify_proc.m:
	Avoid hard-coding "mercury_builtin" by instead
	calling one of  mercury_{private,public}_builtin_module/1.

runtime/mercury_type_info.[ch]:
library/term.m:
library/std_util.m:
compiler/code_util.m:
	Change a few hard-coded instances of "mercury_builtin"
	to "builtin" or "private_builtin" as appropriate.

runtime/mercury_trace_util.c:
runtime/mercury_trace_internal.c:
library/prolog.m:
compiler/*.m:
	Update comments that refer to "mercury_builtin" to instead
	refer to either "builtin" or "private_builtin".

doc/Mmakefile:
	Don't include the interface to private_builtin.m in the
	library reference manual.

tools/bootcheck:
	Add `-p'/`--copy-profiler' option.  This is needed to get
	the above changes to bootstrap.

tools/test_mercury:
	Pass `-p' to tools/bootcheck.

tests/term/*.trans_opt_exp:
	s/mercury_builtin/builtin/g
1998-05-25 21:55:28 +00:00
Fergus Henderson
986b631dc6 Add code to parse terms from strings rather than from streams.
Estimated hours taken: 24

Add code to parse terms from strings rather than from streams.
The original intention for this change was twofold:
to increase expressiveness and to improve efficiency.
However, for the moment I have given up on the goal of
improving efficiency.

library/io.m:
	Add io__read_file_as_string/{4,5}, for efficiently
	reading a whole file into a single string.
	Add io__read_from_string/5, for reading terms of
	any type from a string.
	(Should that instead be named string__read instead?)

library/string.m:
	Implement string__substring/4 more efficiently,
	using `pragma c_code' rather than by calling
	string__right(string__left(...)).
	Export string__unsafe_index/3, and add new exported
	predicate string__unsafe_substring/4 -- these
	are versions of string__index and string__substring
	that don't check for range errors.  They are
	needed to get reasonable efficiency when dealing
	with very large strings.

library/string.nu.nl:
	Add Prolog implementations of string__substring
	and string__unsafe_substring.

library/lexer.m:
	Add lexer__string_get_token_list/{5,6}, for parsing
	tokens from a string.  This required adding
	`string_' versions of most of the lexical analysis routines.
	XXX lots of code duplication, I'm afraid.
	XXX the string versions are not as efficiency as they
	    could ideally be.

library/parser.m:
	Add new predicates parser__read_term_from_string/{4,6}
	and parser__parse_token_list.

compiler/bytecode_gen.m:
compiler/error_util.m:
compiler/fact_table.m:
compiler/term_errors.m:
	Minor changes to use term__context as an ADT rather than
	as a concrete data type.

In addition, I made the following changes, which I am NOT committing.

compiler/prog_io.m:
	Change to use io__read_file_as_string and
	parser__read_term_from_string.
	(Not committed because the existing method is
	in currently more efficient.)

library/term.m:
	Add new alternative term__detailed_context to the term__context type.
	This alternative can record both the start and end of a term rather
	than just the end.
	(The lexer now has almost all the necessary support for detailed
	contexts, but enabling it would have some potentially significant
	efficiency costs, and curently the parser uses only single contexts
	rather than ranges; so currently this is not used.)
1998-05-21 16:52:20 +00:00
David Jeffery
24db091286 Fix a variable renaming bug in the recently introduced changes to
Estimated hours taken: 4

Fix a variable renaming bug in the recently introduced changes to
check_typeclass.m.

compiler/check_typeclass.m:
        When adding constraints from the instance declaration to the
        generated predicate, rename them apart from the vars of the
        class declaration.

        This is only a concern where a class method uses type variables
        that are not parameters of the class, so was missed by the test
        cases.

Test case coming soon (as soon as I can cut it down a bit).
1998-05-21 12:32:02 +00:00
David Jeffery
c273ecdbcc A re-work of check_typeclass.m. Now, rather than the ad-hoc approach of
Estimated hours taken: 25

A re-work of check_typeclass.m. Now, rather than the ad-hoc approach of
checking each method of each instance declaration for *exact* type and mode
correctness, we generate a new predicate that gets inserted into the HLDS.
This predicate is checked for type, mode, uniqueness and determinism
correctness in the appropriate compiler pass.

As a consequence, the check_typeclass pass now has to come before typecheck.m.
Previously, it was the final semantic analysis pass because it had to use
type, mode, uniqueness and determinism information. The new approach does not
need that information to be available.

This has the following user-visible improvements:
	- constraints on class methods are now checked properly. An
	  instance's implementation of a method may be less constrained.
	  (Previously, these constraints weren't even checked at all. Oops).
	- a method implementation may be more polymorphic than expected
	- implied modes will be used for methods if necessary

This is a much more robust approach (and it co-incides with the typeclass
paper ;-) ).

compiler/check_typeclass.m:
	Introduce the auxiliary predicate for the instance method. As an
	optimisation, do not introduce the predicate if the implementation
	given is an *exact* match (in terms of types, modes and determinism).
compiler/mercury_compile.m:
	Put the check_typeclass pass before typechecking.
compiler/type_util.m:
	Change type_list_matches_exactly to
	type_and_constraint_list_matches_exactly since check_typeclass is
	also responsible for checking constraints on method implementations.
	(This is only used in the optimisation mentioned above).
1998-05-20 17:58:03 +00:00
Fergus Henderson
44a5c5b2f8 Make the code a little bit more readable:
Estimated hours taken: 6

compiler/mercury_to_mercury.m:
compiler/mode_errors.m:
	Make the code a little bit more readable:
	use specific types rather than `bool' in a few places.

compiler/mercury_to_mercury.m:
	Fix bugs in the generation of interface files where it was
	outputting certain graphic tokens incorrectly.  In particular,
	it was outputting things like `module:?' without any parentheses,
	space, or quotes to separate the `:' as module qualifier from
	the symbol name.

tests/hard_coded/Mmakefile:
tests/hard_coded/quoting_bug.m:
tests/hard_coded/quoting_bug_test.m:
tests/hard_coded/quoting_bug_test.exp:
	Add some tests for the above-mentioned bug fix.

tests/term/*.trans_opt_exp:
tests/misc_tests/pretty_print_test.exp:
	Update expected output for these tests to reflect the
	above changes.
1998-05-20 13:10:50 +00:00
Fergus Henderson
6921e0e015 Add a `--debug' option for Mercury-level debugging
Estimated hours taken: 6

Add a `--debug' option for Mercury-level debugging
using the trace-based debugger.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/ml.in:
compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
	Split the old `--debug' option into `--low-level-debug'
	(formerly the absence of -DSPEED, now handle by -DLOWLEVEL_DEBUG)
	and `--c-debug' (passes -g to C compiler).
	Delete the old `debug' grade.
	Add support for new options `--require-tracing'
	(makes --trace minimum equivalent to --trace interfaces,
	and passes -DMR_REQUIRE_TRACING to C compiler)
	`--stack-trace' (passes -DMR_STACK_TRACE to C compiler;
	actually this one was already supported)
	and `--debug' (implies previous two),
	with corresponding grade modifiers `.trace', `.strce', and `.debug'.
	Actually I think there's little point in specifying just one
	of `--require-tracing' and `--stack-trace' so for the moment
	I'm just providing `--debug': the code for the more fine-grained
	options and grade modifiers has been added but commented out.

runtime/mercury_conf_param.h:
	Document the new configuration parameter MR_REQUIRE_TRACING
	and the existing but undocumented parameter MR_STACK_TRACE.

runtime/mercury_grade.h:
	Include MR_REQUIRE_TRACING in the mangled grade identifier.

compiler/globals.m:
compiler/handle_options.m:
compiler/options.m:
	Allow new tracing type `--trace default', and make it the default.
	This gets replaced with `full' if require_tracing is yes
	or `minimal' if require_tracing is no.
	Also `--trace minimum' gets replaced with `interface' if
	require_tracing is yes.

doc/user_guide.texi:
	Document the new `--debug', `--low-level-debug', and `--c-debug'
	options.

scripts/mgnuc.in:
compiler/mercury_compile.m:
doc/user_guide.texi:
	Change things so that `--c-debug' does not imply `--no-c-optimize'.

configure.in:
	Add `-fomit-frame-pointer' to CFLAGS_FOR_GOTOS on alpha-*.
	Empirically, this seems to be needed, otherwise lots of
	the test cases fail when compiled with `--no-c-optimize'.
	(It might also be needed for other architectures, I don't know.)
1998-05-20 11:11:57 +00:00
Zoltan Somogyi
2f2a450ed0 Move the number of type parameters from the label layout structures
Estimated hours taken: 2

compiler/stack_layout.m:
	Move the number of type parameters from the label layout structures
	to the start of the vector of type parameter locations. Since
	different labels' layouts often have the same set of typeinfo variable
	locations, this saves one word on a large fraction of all label
	layout tables.

	Fix some documentation rot.

runtime/mercury_stack_layout.h:
	Make the corresponding change in the C description of the layout
	structure.

runtime/mercury_trace_internal.c:
	Make the corresponding change in the C code that accesses the layout
	structure.

	Fix an earlier oversight: don't try to materialize type parameters
	that aren't live.
1998-05-19 05:15:10 +00:00
Oliver Hutchison
b6bf9d583b Fix bug in generation of dependencies for files containing a pragma
Estimated hours taken: 0.01

Fix bug in generation of dependencies for files containing a pragma
`fact_table' declaration. There was an extra .o appended to the end
of the object files that the fact table depended on, this caused Mmake to
fail.

compiler/modules.m :
	Remove extraneous ".o" being output to dependency file.
1998-05-18 03:18:37 +00:00
Fergus Henderson
9a2b9a8ef0 Update the error message about invalid `--trace' arguments
Estimated hours taken: 0.25

compiler/handle_options.m:
	Update the error message about invalid `--trace' arguments
	to reflect the new names.

tests/debugger/Mmakefile:
	Change `--trace full' to `--trace all'
	to reflect the new names for `--trace arguments'.
1998-05-18 02:04:57 +00:00
Fergus Henderson
4845a3782b Fix a typo in Zoltan's changes for tracing: s/"mininum"/"minimum"/
Estimated hours taken: 0.1

compiler/globals.m:
	Fix a typo in Zoltan's changes for tracing: s/"mininum"/"minimum"/
1998-05-17 07:18:21 +00:00
Fergus Henderson
af0908e677 Fix a bug: the default --trace' should be --trace minimum'
Estimated hours taken: 0.25

compiler/options.m:
	Fix a bug: the default `--trace' should be `--trace minimum'
	not `--trace minimal'.

compiler/handle_options.m:
	Unwrap some lines that didn't need to be wrapped.
1998-05-16 22:32:42 +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
Oliver Hutchison
bcf7dbf9f8 Add support for tabling.
Estimated hours taken: 250

Add support for tabling.

This change allows for model_det, model_semidet and model_non memoing,
minimal model and loop detection tabling.

compiler/base_type_layout.m:
	Update comments to reflect new runtime naming standard.

compiler/det_analysis.m:
	Allow tabling to change the result of det analysis. This is
	necessary in the case of minimal model tabling which can
	turn a det procedure into a semidet one.

compiler/det_report.m:
compiler/hlds_data.m:
	Add code to report error messages for various non compatible
	tabling methods and determinism.

compiler/hlds_out.m:
compiler/modules.m:
	Remove reference to the old memo marker.

compiler/hlds_pred.m:
	Create new type (eval_method) to define which of the available
	evaluation methods should be used each procedure.
	Add new field to the proc_info structure.
	Add several new predicates relating to the new eval_method type.

compiler/inlining.m:
compiler/intermod.m:
	Make sure only procedures with normal evaluation are inlined.

compiler/make_hlds.m:
	Add code to process new tabling pragmas.

compiler/mercury_compile.m:
	Call the tabling transformation code.

compiler/modes.m:
	Make sure that all procedures with non normal evaluation have
	no unique/partially instantiated modes. Produce error messages
	if they do. Support for partially instantiated modes is currently
	missing as it represents a large amount of work for a case that
	is currently not used.

compiler/module_qual.m:
compile/prog_data.m:
compiler/prog_io_pragma.m:
	Add three new pragma types:
		`memo'
		`loop_check'
		`minimal_model'
	and code to support them.

compiler/simplify.m:
	Don't report infinite recursion warning if a procedure has
	minimal model evaluation.

compiler/stratify.m:
	Change the stratification analyser so that it reports cases of
	definite non-stratification. Rather than reporting warnings for
	any code that is not definitely stratified.
	Remove reference to the old memo marker.

compiler/switch_detection.m:
	Fix a small bug where goal were being placed in reverse order.
	Call list__reverse on the list of goals.

compiler/table_gen.m:
	New module to do the actual tabling transformation.

compiler/notes/compiler_design.html:
	Document addition of new tabling pass to the compiler.

doc/reference_manual.texi:
	Fix mistake in example.

library/mercury_builtin.m:
	Add many new predicates for support of tabling.

library/std_util.m:
library/store.m:
	Move the functions :
		ML_compare_type_info
		ML_collapse_equivalences
		ML_create_type_info
	to the runtime.

runtime/mercury_deep_copy.c:
runtime/mercury_type_info.h:
runtime/mercury_type_info.c:
	Move the make_type_info function into the mercury_type_info module
	and make it public.

runtime/Mmakefile:
runtime/mercury_imp.h:
	Add references to new files added for tabling support.

runtime/mercury_string.h:
	Change hash macro so it does not cause a name clash with any
	variable called "hash".

runtime/mercury_type_info.c:
runtime/mercury_type_info.h:
	Add three new functions taken from the library :
		MR_compare_type_info
		MR_collapse_equivalences
		MR_create_type_info.

runtime/mercury_table_any.c:
runtime/mercury_table_any.h:
runtime/mercury_table_enum.c:
runtime/mercury_table_enum.h:
runtime/mercury_table_int_float_string.c:
runtime/mercury_table_int_float_string.h:
runtime/mercury_table_type_info.c:
runtime/mercury_table_type_info.h:
runtime/mercury_tabling.h:
	New modules for the support of tabling.
1998-05-15 07:09:29 +00:00
Fergus Henderson
49c25842cf Fix a problem reported by Baudouin Le Charlier <ble@info.fundp.ac.be>
where switch detection was getting confused by explicit existential
quantifications.

compiler/switch_detection.m:
	When detecting switches, traverse through some/2 goals.
	Also simplify the code a bit.

tests/valid/Mmakefile:
tests/valid/some_switch.m:
	Regression test for the above change.
1998-05-12 17:05:04 +00:00
David Jeffery
128b630a9a Re-implement the part of context reduction which seeks to eliminate a
Estimated hours taken: 15

Re-implement the part of context reduction which seeks to eliminate a
typeclass constraint by using the fact that one class is a superclass of
another. This achieves two things:
        - Fixes a bug, in that the new algorithm (correctly) searches the whole
                    superclass relation to find a path from one constraint to
          another.
        - It makes the algorithm the same as what we put in the type class
                    paper. :-)

compiler/check_typeclass.m:
        Pass the super class table to the context reduction predicate
compiler/hlds_data.m:
        Declare the types which (explicitly) hold the superclass information
compiler/hlds_module.m:
        Store the superclass information explicitly in the module_info, rather
        than just implicitly in the class_table
compiler/make_hlds.m:
        Explicitly construct the superclass information as classes are added.
        This saves re-computing it for each constraint in typecheck.m
compiler/typecheck.m:
        Use the explicit superclass information for context reduction, rather
        than just the class table.

        When reducing the context using superclasses, recursively search the
        whole superclass relation until a match is found.
1998-05-07 06:41:50 +00:00
Fergus Henderson
76339b06c1 Avoid some spurious warning messages.
Estimated hours taken: 0.25

Avoid some spurious warning messages.

compiler/modules.m:
	Don't warn "module doesn't export anything"
	for modules which export sub-modules.
1998-05-06 08:32:51 +00:00
Simon Taylor
c95ddbceec Disable deforestation, since it breaks a couple of test cases.
Estimated hours taken: 0.01

compiler/options.m
	Disable deforestation, since it breaks a couple of test cases.
1998-04-28 06:12:38 +00:00
Simon Taylor
b8a8b520a3 Forgot to `cvs add' this one.
Estimated hours taken: 0.001

compiler/deforest.m
	Forgot to `cvs add' this one.
1998-04-27 07:17:33 +00:00
Simon Taylor
75354e38bb Deforestation.
Estimated hours taken: 400

Deforestation.

This increases the code size of the compiler by ~80k when compiling
with --intermodule-optimization --deforestation.

The improvement from deforestation is not measurable for mmc -C make_hlds.m.
Compile time for make_hlds.m increased from 50.7 seconds to 52.2 seconds
when running deforestation.

compiler/simplify.m
compiler/common.m
	Provide a nicer interface for simplifying a goal,
	not an entire procedure.
	Rework the interface to avoid manipulating lots of booleans.
	Return an estimate of the improvement in cost from simplification.
	Remove failing cases and disjuncts.
	Add an option to optimize common structures even across calls.
	Remove code to merge branched goals, since that is now
	done by deforestation.

	Fix a bug: the code to collect instmap_deltas for cases was not
	including the switched-on variable in the instmap_delta,
	which caused an abort in merge_instmap_delta if the switched
	on variable was further instantiated in the switch.
	This came up while compiling the compiler with --deforestation.

compiler/det_report.
	Output duplicate call warnings even if --warn-simple-code is not set.
	XXX fix the same problem with `:- pragma obsolete'.

compiler/code_aux.m
	Update code_aux__cannot_loop to use termination information.

compiler/hlds_pred.m
compiler/dnf.m
	Pass the type_info_varmap and typeclass_info_varmap
	into hlds_pred__define_new_pred.
	Restrict the variables of the new procedure onto the variables
	of the goal.
	Make sure all relevant type_infos are passed into the new
	procedure if --typeinfo-liveness is set.

compiler/modes.m
compiler/unique_modes.m
compiler/mode_info.m
compiler/modecheck_unify.m
	Put `how_to_check_goal' into the mode_info, rather
	than passing it around.
	Add a field to the `check_unique_modes' case which
	controls whether unique modes is allowed to choose
	a different procedure. For deforestation, this is
	not allowed, since it could result in choosing a less
	efficient procedure after generalisation.

compiler/options.m
	New options:
	--deforestation
	--deforestation-depth-limit
		Safety net for termination of the algorithm.
	--deforestation-cost-factor
		Fudge factor for working out whether deforestation
		was worthwhile.
	--deforestation-vars-threshold
		Like --inline-vars-threshold.
	Enable deforestation at -O3.

	Removed an unnecessary mode for option_defaults_2, since it
	resulted in a warning about disjuncts which cannot succeed.

compiler/handle_options.m
	--no-reorder-conj implies --no-deforestation.

compiler/inlining.m
	Separate code to rename goals into inlining__do_inline_call.

compiler/hlds_goal.m
	Added predicates goal_list_nonlocals, goal_list_instmap_delta
	and goal_list_determinism to approximate information about
	conjunctions.

compiler/hlds_module.m
	Added module_info_set_pred_proc_info to put an updated
	pred_info and proc_info back into the module_info.

compiler/hlds_out.m
	Exported hlds_out__write_instmap for debugging of deforestation.
	Bracket module names on constructors where necessary.

compiler/mercury_compile.m
	Call deforestation.
	Use the new interface to simplify.m.

compiler/intermod.m
	Put recursive predicates with a top-level branched goal
	into `.opt' files.

goal_util.m
	Added goal_calls_pred_id to work out if a predicate is
	recursive before mode analysis.
	Export goal_util__goals_goal_vars for use by deforestation.
	Give a better message for a missing variable in a substitution.

compiler/instmap.m
	Give a better message for inst_merge failing.

compiler/notes/compiler_design.m
	Document the new modules.

library/varset.m
	Add varset__select to project a varset's names and values
	onto a set of variables.

doc/user_guide.texi
	Document deforestation.
	Remove a reference to a non-existent option, --no-specialize.

util/mdemangle.c
profiler/demangle.m
tests/misc_tests/mdemangle_test.{exp,inp}
	Handle the `DeforestationIn__' predicate names introduced by
	deforestation, similar to the `IntroducedFrom__' for lambda goals.

New files:

deforest.m	Deforestation.
pd_cost.m	Cost estimation.
pd_debug.m	Debugging output.
pd_info.m	State type and version control.
pd_term.m	Termination checking.
pd_util.m	Utility predicates
1998-04-27 04:05:12 +00:00
Tyson Dowd
484d842a34 Fix stack traces, which were broken with recent tracing code changes.
Estimated hours taken: 4

Fix stack traces, which were broken with recent tracing code changes.

compiler/continuation_info.m:
compiler/mercury_compile.m:
	Collect continuation label information for stack traces, but
	without the liveness information that is needed for agc.

compiler/stack_layout.m:
	Add a comment stating that changes in this file may need to be
	reflected in runtime/mercury_stack_layout.h
1998-04-17 06:55:40 +00:00
Zoltan Somogyi
32284569e8 Use bintree_set instead of set to represent the set of things declared
Estimated hours taken: 2

compiler/llds_out:
	Use bintree_set instead of set to represent the set of things declared
	so far. Although this causes a very slight slowdown (comparable to
	timing noise) in the usual case, it is a significant improvement
	with --generate-trace, especially on large files.

	When compiling llds_out.m itself this way, these change reduces the
	amount of memory allocated while writing out the .c file from almost
	53 Mb to about 35 Mb, with an even bigger reduction (more than a factor
	of 5) in the number of calls to GC_malloc.

	Avoid the use of string__format for a frequent trivial task.
	This helps a bit too.
1998-04-15 06:49:27 +00:00
Fergus Henderson
7f261f912b A few more improvements to type class checking.
Estimated hours taken: 4

A few more improvements to type class checking.

compiler/typecheck.m:
	Ensure that we run a final pass of context reduction at the
	end of typechecking each predicate (or function).

	Change the way perform_context_reduction recovers after errors
	to avoid reporting the same error more than once
	(e.g. for tests/invalid/typeclass_test_2.m).

	Simplify the code to check for and report unsatisfied
	type class constraints.

	Change write_type_assign so that it prints out the
	type class constraints as well as the variable types.

tests/invalid/typeclass_test_*.err_exp:
	Add a full stop that was missing at the end of
	the "unsatisfied typeclass constraint" error message.
1998-04-09 18:33:13 +00:00
Fergus Henderson
70f36b70e0 Add a comment (as suggested by DJ's review).
Estimated hours taken: 0.1

compiler/typecheck.m:
	Add a comment (as suggested by DJ's review).
1998-04-09 15:29:33 +00:00
Fergus Henderson
5e86fb5715 Fix some bugs in the handling of "non-simple" type class constraints
Estimated hours taken: 12

Fix some bugs in the handling of "non-simple" type class constraints
(ones for which the types being constrained are not just type variables).

compiler/prog_io_typeclass.m:
	Ensure that constraints on type class declarations must be "simple".
	This is needed the ensure termination of type checking.
	(We already did this for instance declarations, but not for
	superclass constraints on type class declarations.)

compiler/prog_data.m:
	Document the invariant that the types in a type class constraint
	must not contain any information in their term__context fields.

compiler/type_util.m:
compiler/equiv_type.m:
compiler/polymorphism.m:
compiler/prog_io_typeclass.m:
	Enforce the above-mentioned invariant.

compiler/typecheck.m:
	Allow the declared constraints to be a superset of the
	inferred constraints.
	When performing context reduction, eliminate declared
	constraints at each step rather than only at the end.
	Remove declared constraints and apply superclass rules
	before applying instance rules.
	When applying instance rules, make sure that it is a type
	error if there is no matching instance rule for a ground
	constraint.
	If context reduction results in an error, restore the
	original type assign set, to avoid repeating the same
	error message at every subsequent call to perform_context_reduction.

compiler/check_typeclass.m:
	Change the way we superclass conformance for instance declarations
	to take advantage of the new "DeclaredConstraints" argument to
	typecheck__reduce_context_by_rule_application.
1998-04-08 15:23:35 +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
Fergus Henderson
ab7ce6c430 Fix a variable numbering bug in my last change.
Estimated hours taken: 0.1

compiler/mercury_compile.m:
	Fix a variable numbering bug in my last change.
1998-04-01 15:05:23 +00:00
Fergus Henderson
f025115d14 Change the order of the passes to match that specified in
Estimated hours taken: 0.25

compiler/mercury_compile.m:
	Change the order of the passes to match that specified in
	notes/compiler_design.html: invoke check_typeclass.m
	(which checks the correctness of instance declarations)
	immediately after unique mode checking, before simplify.m
	and stratify.m.

	Note that for the purposes of mode inference, it would be
	nice to run a pass similar to the current check_typeclass
	pass *before* mode inference; this pass would would insert modes
	for all predicates declared as being instance methods, so that
	we can do mode inference for such procedures even if the only
	call is via instance methods.
1998-03-30 13:30:57 +00:00
Fergus Henderson
0d117f424c Get type inference working for type classes.
Estimated hours taken: 2

compiler/typecheck.m:
	Get type inference working for type classes.

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/inference_test.m:
tests/hard_coded/typeclasses/inference_test.exp:
	Add a simple test case for type class inference.
1998-03-30 13:28:21 +00:00
Fergus Henderson
6f065be64a Fix some Mmakefile errors that were diagnosed by `--warn-undefined-variables'.
Estimated hours taken: 1

Fix some Mmakefile errors that were diagnosed by `--warn-undefined-variables'.
Also, make a small fix to mmake.in and add empty definitions for various
Mmake variables to avoid spurious warnings.

scripts/mmake.in:
	Add ` dep*' to the patterns for which we do not
	pass `--warn-undefined-variables'; previously it
	matched "$@" against `dep*', which did not catch the
	case of `mmake -k depend'.
		       ^^^

scripts/Mmake.vars.in:
	Add definition for `ds_subdir'.
	Define `MLLIBS' as `$(EXTRA_MLLIBS)' rather than empty,
	and add empty definition for `EXTRA_MLLIBS'.
	Add empty definition for `MAIN_TARGET'.

Mmakefile:
	Fix misspelling: `deps_subdir' not `dep_subdir'.
	Add empty definitions for `PREINSTALL_HACK', `POSTINSTALL_HACK',
	and `MMAKEFLAGS'.

boehm_gc/Mmakefile:
	Add empty definition for `PROF'.

runtime/Mmakefile:
	Add empty definition for `DLL_CFLAGS'.

library/Mmakefile:
	Add empty definition for `CHECK_TERM_OPTS'.

compiler/Mmakefile:
	Add empty definition for `MTAGSFLAGS'.
1998-03-30 13:03:17 +00:00
Andrew Bromage
2b5f65707f Include some verbose progress messages in the polymorphism pass.
Estimated hours taken: 0.5

compiler/mercury_compile.m:
compiler/polymorphism.m:
	Include some verbose progress messages in the polymorphism pass.

runtime/mercury_memory.h:
runtime/mercury_memory.c:
runtime/mercury_misc.h:
runtime/mercury_misc.c:
	Move checked_malloc() to mercury_memory.c, add checked_realloc().
1998-03-30 03:09:06 +00:00