Commit Graph

70 Commits

Author SHA1 Message Date
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
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
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
Fergus Henderson
1481544541 Fix the handling of dependencies on $(MLOBJS) and $(MLPICOBJS)
Estimated hours taken: 0.5

Fix the handling of dependencies on $(MLOBJS) and $(MLPICOBJS)
so that we don't reinvoke the linker for every make, even when
the executable(s) are already up-to-date.

scripts/Mmake.rules:
	Delete the MLOBJS and MLPICOBJS targets.
	Add `$(MLOBJS_DEPS) : $(MLOBJS)', and likewise for $(MLPICOBJS).

compiler/modules.m:
	When generating the `.dep' files, instead of using the MLOBJS
	and MLPICOBJS phony targets, record dependencies of files on
	$(MLOBJS) by adding those files to $(MLOBJS_DEPS),
	and likewise for $(MLPICOBJS).
1998-03-20 05:53:27 +00:00
Fergus Henderson
d05cf3506c Improve the efficiency of `--use-subdirs' slightly by reducing
Estimated hours taken: 0.5

Improve the efficiency of `--use-subdirs' slightly by reducing
the size of the generated `.dep' files.

compiler/modules.m:
	When generating the .dep file with `--use-subdirs' enabled,
	don't disable compact dependency lists, instead use the
	$(cs_subdir), $(os_subdir) etc. variables to make them work.
1998-03-20 04:36:19 +00:00
Fergus Henderson
7ebc79e927 Fix some problems with the `--use-subdirs' option.
Estimated hours taken: 6

Fix some problems with the `--use-subdirs' option.
The compiler itself now compiles and bootstraps fine with --use-subdirs.

compiler/modules.m:
	Put `.h' files in the source directory, rather than
	in the `Mercury/hs' subdirectory.

compiler/mercury_compile.m:
scripts/Mmake.rules:
	If `--use-subdirs' is enabled, pass `-I.' to the C compiler,
	so that #include statements work relative to the source directory
	rather than relative to the `Mercury/cs' subdirectory.

scripts/Mmake.vars.in:
	Define $(cs_subdir), $(os_subdir) etc. variables;
	these are set to the directory to use for .c, .o, etc. files,
	(including the trailing `/'), or to the empty string,
	if --use-subdirs is not set.

scripts/Mmake.rules:
	Use $(cs_subdir), $(os_subdir) etc. to avoid the code
	duplication created by my previous change to handle
	--use-subdirs.
	Also add lots of comments, and reorder the code
	in a more logical order.

Mmakefile:
library/Mmakefile:
compiler/Mmakefile:
profiler/Mmakefile:
tests/term/Mmakefile:
tests/valid/Mmakefile:
	Use $(cs_subdir), $(os_subdir) etc. to fix a few hard-coded
	file-names (e.g. *.dep, *_init.[co], tree234.o) that were
	used in some of the rules.

library/Mmakefile:
	Add `rm -f tags' to the rule for `mmake realclean'.

tools/bootcheck:
	Add `--use-subdirs' option (defaults to setting of the
	MMAKE_USE_SUBDIRS environment variable).
	Change the code which compares the stage2 & stage3 C files
	to use the appropriate location for them based on the
	setting of this option.
1998-03-20 02:58:33 +00:00
Fergus Henderson
f4caf49a15 Fix a limitation of the current nested module support:
Estimated hours taken: 4

Fix a limitation of the current nested module support:
ensure that we check for attempts to import inaccessible modules.

compiler/modules.m:
	Check for attempts to import inaccessible modules
	(modules whose parent has not been imported,
	or for which there is no `include_module'
	declaration in the parent's interface).

compiler/intermod.m:
	Modify the way we import `.opt' files.  The previous method
	temporarily set the items field of the module_imports
	structure to [], but check_module_accessibility relies
	on the assumption that the items field contains the
	items for all modules previously read in.

tests/invalid/Mmakefile:
tests/invalid/test_nested.m:
tests/invalid/test_nested.err_exp:
tests/invalid/parent.m:
tests/invalid/parent.private_child.m:
tests/invalid/parent.public_child.m:
tests/invalid/parent.undeclared_child.m:
tests/invalid/parent.undeclared_child.err_exp:
tests/invalid/parent2.m:
tests/invalid/parent2.child.m:
	Add some tests for the above change.

doc/reference_manual.texi:
	Update the "bugs and limitations" sub-section of the modules
	chapter to reflect the new status quo.
1998-03-18 17:31:08 +00:00
Fergus Henderson
f884cee0c4 Finish off the centralization of the file name handling code, and
Estimated hours taken: 11

Finish off the centralization of the file name handling code, and
add support for generating intermediate files in subdirectories.

scripts/mmake.in:
	Add a new boolean option `--use-subdirs';
	if enabled, it just sets the environment variable MMAKE_USE_SUBDIRS
	to `yes' before invoking Make.
	Also add negative versions of the various options
	(`--no-use-subdirs', `--no-verbose', `--no-save-makefile').

scripts/Mmake.rules:
	Add code to handle generating intermediate file names
	in subdirectories.  If MMAKE_USE_SUBDIRS=yes, we add
	`--use-subdirs' to MCFLAGS, and most of the pattern rules
	are changed to use subdirectories.

	Note that getting this to work required a bit of a hack:
	due to what seem to be bugs in GNU Make, `mmake depend'
	needs to do `mmc --make-short-interface *.m' to get things
	started.  But once the int3s are there, the dependencies
	seem to work OK.

compiler/options.m:
	Add a new boolean option `--use-subdirs'.

compiler/modules.m:
	Add new predicate `fact_table_file_name'.
	Add an extra argument to `module_name_to_file_name',
	specifying whether or not to create any directories
	needed for the file name.
	Change all the file-name-creating predicates here
	to go through a single new predicate `choose_file_name',
	and add code in that predicate to handle the `--use-subdirs'
	option.
	Also if the `--use-subdirs' option is set, don't use the
	compact dependencies format, since it can't work in that case.

compiler/fact_table.m:
	Call `fact_table_file_name' rather than using `string__append'.

compiler/mercury_compile.m:
	Change `link_module_list' and `join_module_list'
	so that they create file names by calling `module_name_to_file_name'.

compiler/export.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/termination.m:
compiler/trans_opt.m:
compiler/unused_args.m:
	Change all calls to `module_name_to_file_name' to pass
	the extra argument specifying whether or not to make
	any directories needed for the file name.

library/Mmakefile:
	Change the rule for `mmake install_ints' so that it
	creates a `Mercury' subdirectory with symbolic links
	`ints', `int2s', `int3s', `opts', and `trans_opts'
	which just point to `..'.  This is needed for the
	`--use-subdirs' option to work, because Mmake currently
	does not support mixing libraries compiled with and
	without `--use-subdirs'.

doc/user_guide.texi:
	Document the above changes.
1998-03-18 08:09:50 +00:00
Fergus Henderson
c87d89ec4c Change things so that almost all the places which create file names
Estimated hours taken: 4.5

Change things so that almost all the places which create file names
do so via just a few predicates (such as module_name_to_file_name)
in modules.m.  Centralising the file handling in this way
will make future changes to the file naming convention simpler.

(The one place which still creates file names other than via the predicates
declared at the start of modules.m is mercury_compile__link_module_list.
It creates them based on the value of the `-o <filename>' option.
I didn't change that because I am not yet sure what the semantics of
the `-o <filename>' option ought to be.)

compiler/modules.m:
	Add three extra arguments to module_name_to_file_name/2:
	the file extension, and an io__state pair.
	Add new predicates module_name_to_lib_file_name/6,
	module_name_to_split_c_file_name/6, and
	module_name_to_make_var_name/2.

compiler/export.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/termination.m:
compiler/trans_opt.m:
compiler/unused_args.m:
	Change all calls to module_name_to_file_name/2 to instead
	call one of the above-mentioned predicates in modules.m.

compiler/llds_out.m:
	Add new predicate llds_out__make_init_name/2 which returns
	the name of the initialization function for a module,
	for use by modules.m.

compiler/modules.m:
	A few minor changes to the generated .dep files:
		- add a new phony target `foo.trans_opt',
		  to match `foo.opt';
		- change the generated rule for `change_clean'
		  so that it removes `.pic_o' files;
		- add `.PHONY' declarations for phony targets;
		- change the generated rule for making `foo.init'
		  so that it used the names returned by
		  llds_out__make_init_name/2, rather than
		  using "mercury__`basename foo.m .m`__init";
		- fix a bug in the generated rule for making `libfoo.a':
		  it had `rm -f foo.a' instead of `rm -f libfoo.a'.
1998-03-17 00:28:19 +00:00
Fergus Henderson
1771c56ac6 Fix a bug that I introduced in modules.m.
Estimated hours taken: 0.5

Fix a bug that I introduced in modules.m.
The log message for my previous change was:

        - generate_dependencies was using the transitive implementation
	  dependencies rather than the transitive interface dependencies
	  to compute the `.int3' dependencies when writing `.d' files
	  (this bug was introduced during crs's changes to support
	  `.trans_opt' files)

Unfortunately using the transitive interface dependencies is not quite
right either.  You need to take the composition of the implementation
dependencies and the transitive interface dependencies.
For the moment I'll just back out this change, since the impact of the
previous bug was much less than the impact of the one I replaced it with.
1998-03-06 09:05:12 +00:00
Tyson Dowd
164369cd14 Fix bugs in how MLOBJS works.
Estimated hours taken: 3

Fix bugs in how MLOBJS works.

Because mmake puts the contents of the .dep file before the Mmakefile
when generating a makefile for gmake, the scheme of using
        MLOBJS=foo.o bar.o
in the Mmakefile won't work.

The dependencies in the .dep file such as
        libxyz.a: ..... $(MLOBJS)
are expanded when read, but the variable MLOBJS is not set until later.
This means MLOBJS won't be generated from the .c files, and the linker
will abort, complaining that files are missing.

So the solution is to output
        libxyz.a: ..... MLOBJS
where MLOBJS is a target, and is defined in Mmake.rules (which is seen
by make after the contents of Mmakefile).
        MLOBJS: $(MLOBJS).

(In fact, it gets more complicated: to support different MLOBJS variables
for different programs/libraries, so we use MLOBJS-xyz as the target,
and a pattern matching rule in Mmake.rules).

This must also be done for MLPICOBJS.

compiler/modules.m:
        Output the targets instead of the variables.

scripts/Mmake.rules:
        Pattern match MLOBJS-% and MLPICOBJS-% dependencies, and make
        them depend on the corresponding variables.
1998-03-05 06:01:41 +00:00
Fergus Henderson
3c0063fac0 Add support for the use of partial module qualifiers,
Estimated hours taken: 8

Add support for the use of partial module qualifiers,
e.g. using `child:foo' to refer to `parent🧒foo'.
Previously we only allowed names to be fully-qualified
or completely unqualified.

Note that we still don't yet keep track of which modules are visible,
so this change does not properly handle the distinction between
`import_module' and `use_module' declarations for parent modules.
It basically assumes that `child:foo' is allowed iff plain `foo'
would be allowed (i.e. iff `parent:child' has been imported)
whereas it ought to be allowed iff `parent' has been imported.

compiler/modules.m:
	Add get_partial_qualifiers/2, for use by make_hlds.m
	and hlds_module.m.

compiler/make_hlds.m:
	Insert partially-qualified symbols into the cons_table.

compiler/hlds_module.m:
	Insert partially-qualified symbols into the pred_table.

compiler/module_qual.m:
	When searching the symbol tables used for types, insts, modes,
	and typeclasses, search for partially-qualified symbols.

compiler/modecheck_unify.m:
	When module-qualifying cons_ids, make sure that we fully module
	qualify them even if they're already partially qualified.

tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.child2.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
	Uncomment the previously-failed test of using partially-qualified
	symbol names.  Add a new child module, `parent.child2', and import it
	using `use_module', so that we test `use_module' as well as
	`import_module'.  Add code to test importing of types and
	constructors.
1998-03-04 19:48:04 +00:00
Fergus Henderson
11d8161692 Add support for nested modules.
Estimated hours taken: 50

Add support for nested modules.

- module names may themselves be module-qualified
- modules may contain `:- include_module' declarations
  which name sub-modules
- a sub-module has access to all the declarations in the
  parent module (including its implementation section).

This support is not yet complete; see the BUGS and LIMITATIONS below.

LIMITATIONS
- source file names must match module names
	(just as they did previously)
- mmc doesn't allow path names on the command line any more
	(e.g. `mmc --make-int ../library/foo.m').
- import_module declarations must use the fully-qualified module name
- module qualifiers must use the fully-qualified module name
- no support for root-qualified module names
	(e.g. `:parent:child' instead of `parent:child').
- modules may not be physically nested (only logical nesting, via
  `include_module').

BUGS
- doesn't check that the parent module is imported/used before allowing
	import/use of its sub-modules.
- doesn't check that there is an include_module declaration in the
	parent for each module claiming to be a child of that parent
- privacy of private modules is not enforced

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

NEWS:
	Mention that we support nested modules.

library/ops.m:
library/nc_builtin.nl:
library/sp_builtin.nl:
compiler/mercury_to_mercury.m:
	Add `include_module' as a new prefix operator.
	Change the associativity of `:' from xfy to yfx
	(since this made parsing module qualifiers slightly easier).

compiler/prog_data.m:
	Add new `include_module' declaration.
	Change the `module_name' and `module_specifier' types
	from strings to sym_names, so that module names can
	themselves be module qualified.

compiler/modules.m:
	Add predicates module_name_to_file_name/2 and
	file_name_to_module_name/2.
	Lots of changes to handle parent module dependencies,
	to create parent interface (`.int0') files, to read them in,
	to output correct dependencies information for them to the
	`.d' and `.dep' files, etc.
	Rewrite a lot of the code to improve the readability
	(add comments, use subroutines, better variable names).
	Also fix a couple of bugs:
	- generate_dependencies was using the transitive implementation
	  dependencies rather than the transitive interface dependencies
	  to compute the `.int3' dependencies when writing `.d' files
	  (this bug was introduced during crs's changes to support
	  `.trans_opt' files)
	- when creating the `.int' file, it was reading in the
	  interfaces for modules imported in the implementation section,
	  not just those in the interface section.
	  This meant that the compiler missed a lot of errors.

library/graph.m:
library/lexer.m:
library/term.m:
library/term_io.m:
library/varset.m:
compiler/*.m:
	Add `:- import_module' declarations to the interface needed
	by declarations in the interface.  (The previous version
	of the compiler did not detect these missing interface imports,
	due to the above-mentioned bug in modules.m.)

compiler/mercury_compile.m:
compiler/intermod.m:
	Change mercury_compile__maybe_grab_optfiles and
	intermod__grab_optfiles so that they grab the opt files for
	parent modules as well as the ones for imported modules.

compiler/mercury_compile.m:
	Minor changes to handle parent module dependencies.
	(Also improve the wording of the warning about trans-opt
	dependencies.)

compiler/make_hlds.m:
compiler/module_qual.m:
	Ignore `:- include_module' declarations.

compiler/module_qual.m:
	A couple of small changes to handle nested module names.

compiler/prog_out.m:
compiler/prog_util.m:
	Add new predicates string_to_sym_name/3 (prog_util.m) and
	sym_name_to_string/{2,3} (prog_out.m).

compiler/*.m:
	Replace many occurrences of `string' with `module_name'.
	Change code that prints out module names or converts
	them to strings or filenames to handle the fact that
	module names are now sym_names intead of strings.
	Also change a few places (e.g. in intermod.m, hlds_module.m)
	where the code assumed that any qualified symbol was
	fully-qualified.

compiler/prog_io.m:
compiler/prog_io_goal.m:
	Move sym_name_and_args/3, parse_qualified_term/4 and
	parse_qualified_term/5 preds from prog_io_goal.m to prog_io.m,
	since they are very similar to the parse_symbol_name/2 predicate
	already in prog_io.m.  Rewrite these predicates, both
	to improve maintainability, and to handle the newly
	allowed syntax (module-qualified module names).
	Rename parse_qualified_term/5 as `parse_implicit_qualified_term'.

compiler/prog_io.m:
	Rewrite the handling of `:- module' and `:- end_module'
	declarations, so that it can handle nested modules.
	Add code to parse `include_module' declarations.

compiler/prog_util.m:
compiler/*.m:
	Add new predicates mercury_public_builtin_module/1 and
	mercury_private_builtin_module/1 in prog_util.m.
	Change most of the hard-coded occurrences of "mercury_builtin"
	to call mercury_private_builtin_module/1 or
	mercury_public_builtin_module/1 or both.

compiler/llds_out.m:
	Add llds_out__sym_name_mangle/2, for mangling module names.

compiler/special_pred.m:
compiler/mode_util.m:
compiler/clause_to_proc.m:
compiler/prog_io_goal.m:
compiler/lambda.m:
compiler/polymorphism.m:
	Move the predicates in_mode/1, out_mode/1, and uo_mode/1
	from special_pred.m to mode_util.m, and change various
	hard-coded definitions to instead call these predicates.

compiler/polymorphism.m:
	Ensure that the type names `type_info' and `typeclass_info' are
	module-qualified in the generated code.  This avoids a problem
	where the code generated by polymorphism.m was not considered
	type-correct, due to the type `type_info' not matching
	`mercury_builtin:type_info'.

compiler/check_typeclass.m:
	Simplify the code for check_instance_pred and
	get_matching_instance_pred_ids.

compiler/mercury_compile.m:
compiler/modules.m:
	Disallow directory names in command-line arguments.

compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/modules.m:
	Add a `--make-private-interface' option.
	The private interface file `<module>.int0' contains
	all the declarations in the module; it is used for
	compiling sub-modules.

scripts/Mmake.rules:
scripts/Mmake.vars.in:
	Add support for creating `.int0' and `.date0' files
	by invoking mmc with `--make-private-interface'.

doc/user_guide.texi:
	Document `--make-private-interface' and the `.int0'
	and `.date0' file extensions.

doc/reference_manual.texi:
	Document nested modules.

util/mdemangle.c:
profiler/demangle.m:
	Demangle names with multiple module qualifiers.

tests/general/Mmakefile:
tests/general/string_format_test.m:
tests/general/string_format_test.exp:
tests/general/string__format_test.m:
tests/general/string__format_test.exp:
tests/general/.cvsignore:
	Change the `:- module string__format_test' declaration in
	`string__format_test.m' to `:- module string_format_test',
	because with the original declaration the `__' was taken
	as a module qualifier, which lead to an error message.
	Hence rename the file accordingly, to avoid the warning
	about file name not matching module name.

tests/invalid/Mmakefile:
tests/invalid/missing_interface_import.m:
tests/invalid/missing_interface_import.err_exp:
	Regression test to check that the compiler reports
	errors for missing `import_module' in the interface section.

tests/invalid/*.err_exp:
tests/warnings/unused_args_test.exp:
tests/warnings/unused_import.exp:
	Update the expected diagnostics output for the test cases to
	reflect a few minor changes to the warning messages.

tests/hard_coded/Mmakefile:
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
	Two simple tests case for the use of nested modules with
	separate compilation.
1998-03-03 17:48:14 +00:00
Fergus Henderson
de7b7699ea Fix a bug with parallel makes where the `.d' files were being
Estimated hours taken: 0.75

compiler/modules.m:
	Fix a bug with parallel makes where the `.d' files were being
	stuffed up because two different invocations of the Mercury
	compiler were writing to them at the same time.
	The problem occurs because the `.d' file is written out
	both when creating the `.c' file and when creating the
	`.trans_opt' file, and these steps might happen in parallel.

	The fix is to write the dependency file to a unique temporary
	file name and then rename it to the desired `.d' file name when
	we're done.  This ensures that the update to the `.d' file is atomic.
	[In theory this is not a 100% portable solution, because
	rename() might not be atomic, but in practice it should be
	fine, because rename() is atomic on all the platforms of
	interest (i.e. all the ones that support parallel GNU make).]

	An alternative fix would be to not write out the `.d' files
	when creating `.trans_opt' files.  This would also be more
	efficient.  However, the danger is that the `.d' files might
	not be updated often enough.  I'm not really sure exactly
	how often they need to be updated, but the fix using
	renaming seems safer.  Also the same problem could occur
	when doing `mmake foo.depend bar.depend -j2': if modules
	`foo' and `bar' both import another module `baz', then
	the two processes may attempt to write `baz.d' simultaneously.
	(This happened with printlist.d in the tests/benchmarks directory.)
	So I think the fix using renaming is the right one.
1998-02-27 16:16:31 +00:00
Simon Taylor
9d07a2ccdb Fix a bug reported by Tomas By which caused multiple
Estimated hours taken: 0.5

Fix a bug reported by Tomas By which caused multiple
definition errors when two modules used a third
module, and one of the modules imported the other.

compiler/modules.m
	Delay processing of short interfaces until all long
	interfaces have been read to avoid reading both
	the long and short interface for a module.

tests/valid/module_*.m
	Add a test case.
1998-02-07 09:55:52 +00:00
Fergus Henderson
43131afad7 Print out a warning for clauses (etc.) in module interfaces.
Estimated hours taken: 1

Print out a warning for clauses (etc.) in module interfaces.
This was already done when creating the interface files,
but invalid code could slip past without a warning if
it occured in the topmost module (whose interface is not used,
and hence not created).

compiler/make_hlds.m:
	Print out a warning for clauses or certain pragmas (e.g.
	`pragma c_code') in module interfaces.
	Also inprove the maintainability of the code a little,
	by moving some code out into subroutines.

compiler/modules.m:
	Export pragma_allowed_in_interface/2, for use by make_hlds.m.
1998-01-29 13:42:46 +00:00
Fergus Henderson
274a7c9ae1 Add support to Mmake for new variables MLOBJS and MLPICOBJS,
Estimated hours taken: 2

Add support to Mmake for new variables MLOBJS and MLPICOBJS,
since simply listing object files in MLLIBS doesn't do the
right thing in the case when you're building a library package
rather than a program.

scripts/Mmake.vars.in:
	Add definitions of MLOBJS and MLPICOBJS.

compiler/modules.m:
	Add code to use the $(MLOBJS) and $(MLPICOBJS) variables
	to the rules for building programs and libraries that are
	output in the generated `.dep' files.

doc/user_guide.texi:
	Document the use of MLOBJS and MLPICOBJS.
1998-01-29 13:41:23 +00:00
Fergus Henderson
99c629080c Fix a bug where read_dependency_file_find_start was getting some
Estimated hours taken: 1

compiler/modules.m:
	Fix a bug where read_dependency_file_find_start was getting some
	false hits.  It was supposed to be looking for the first line of

		foo.trans_opt : \
			bar.trans_opt \
			baz.trans_opt

	but because the test was a bit too loose, it was matching

		foo.trans_opt foo.opt ... : \
			bar.int \
			baz.int2

	The effect was that the --warn-missing-trans-opt-deps option
	didn't work.

	Also make the output a bit more consistent by inserting and
	deleting a spaces in a few places.
1998-01-25 06:58:01 +00:00
Fergus Henderson
af21362d44 Add a command to the rule for `mmake clean' int the
Estimated hours taken: 0.25

compiler/modules.m:
	Add a command to the rule for `mmake clean' int the
	generated `.dep' files to remove the `.pic_o' files.
1998-01-22 08:31:48 +00:00
Fergus Henderson
520ad7c9aa A small change to make the code more maintainable: use a det
Estimated hours taken: 0.25

compiler/modules.m:
	A small change to make the code more maintainable: use a det
	predicate pragma_is_allowed_in_interface/2 instead of a semidet
	disjunction.
1998-01-21 05:29:53 +00:00
Fergus Henderson
a70a7099dc Add Mmake support for `.trans_opt' files.
Estimated hours taken: 2

Add Mmake support for `.trans_opt' files.
Also fix up the handling of profiling files for `mmake clean'.

compiler/modules.m:
compiler/trans_opt.m:
	Rename `.trans_optdate' as `.trans_opt_date'.

compiler/modules.m:
	Output definitions for $(foo.profs), $(foo.trans_opts), and
	$(foo.trans_opt_dates) variables in the generated `.dep' files.
	Add code to the generated rules for `mmake clean' to remove
	these files.

scripts/Mmake.rules:
	Add rules for creating `.trans_opt' and `.trans_opt_date' files.
	Change things so that `Prof.*' get removed by `mmake clean'
	rather than only by `mmake realclean'.

scripts/Mmake.vars.in:
	Add MCTOI and MCTOIFLAGS variables, for creating `.trans_opt' files.
1998-01-14 02:21:46 +00:00
Fergus Henderson
e22c6fd3d2 Fix a bug introduced in stayl's changes to add support for
Estimated hours taken: 1

compiler/modules.m:
	Fix a bug introduced in stayl's changes to add support for
	`use_module': it was not reading in the `.int2' files
	for modules indirectly imported from `.int' files.

tests/valid/Mmakefile:
tests/valid/module_a.m:
tests/valid/module_b.m:
tests/valid/module_c.m:
tests/valid/module_d.m:
	A regression test for the above-mentioned bug.
1998-01-09 12:35:16 +00:00
Zoltan Somogyi
e9e971f264 Add a missing period after some progress messages.
Estimated hours taken: 0.1

compiler/{mercury_compile.m,modules.m}:
	Add a missing period after some progress messages.
1998-01-09 07:34:17 +00:00
Christopher Rodd Speirs
d9a891acc0 Fix the processing of .trans_opt files so that circular dependencies
Estimated hours taken: 20

Fix the processing of .trans_opt files so that circular dependencies
cannot occur.  This also guarantees correctness of the information in
the .trans_opt file.

compiler/handle_options.m:
	Add the fact that --transitive-intermodule-optimization implies
	--intermodule-optimization, and that
	--make-transitive-optimization-interface implies
	--transitive-intermodule-optimization.

compiler/mercury_compile.m:
	Add code to read the .d file before new .d files are written.
	The .d file is only read if transitive intermodule optimization
	is enabled.  Also changed the pre-hlds pass so that .d files
	were not written when `error-check only' or `type-check only'
	options were selected.

compiler/modules.m:
	Modified so that the trans_opt dependencies were correctly
	created, and so they were written out to the .d files.  Also
	added new code to read the .d files in.  Removed the
	transitive_dependencies set of predicates as they were no longer
	used.

compiler/options.m:
	Added new option 'warn-missing-trans-opt-deps', to control
	whether warnings are emitted when the dependency information in
	the .d file is lost.  Also uncommented the help messages
	describing transitive-intermodule-optimization.

compiler/trans_opt.m:
	Small changes to trans_opt__grab_optfiles. Also modified the
	comment at the beginning of the file to reflect the current set
	of changes.

doc/user_guide.texi:
	Uncommented the documentation on transitive intermodule
	optimization.
1998-01-06 23:51:17 +00:00
Fergus Henderson
81b373225a Fix a trivial layout error (missing space before `}').
Estimated hours taken: 0.01

compiler/modules.m:
	Fix a trivial layout error (missing space before `}').
1998-01-05 09:53:15 +00:00
Zoltan Somogyi
b4813457c9 A rewrite of termination analysis to make it significantly easier to modify,
Estimated hours taken: 60

A rewrite of termination analysis to make it significantly easier to modify,
and to extend its capabilities.

compiler/error_util.m:
	A new file containing code that makes it easier to generate
	nicely formatted error messages.

compiler/termination.m:
	Updates to reflect the changes to the representation of termination
	information.

	Instead of doing pass 1 on all SCCs and then pass 2 on all SCCs,
	we now do both pass 1 and 2 on an SCC before moving on to the next.

	Do not insist that either all procedures in an SCC are
	compiler-generated or all are user-written, since this need not be
	true in the presence of user-defined equality predicates.

	Clarify the structure of the code that handles builtins and compiler
	generated predicates.

	Concentrate all the code for updating module_infos in this module.
	Previously it was scattered in several places in several files.

	Put all the code for writing out termination information at the
	end of the module in a logical order.

compiler/term_traversal.m:
	A new file containing code used by both pass 1 and pass 2 to
	traverse procedure bodies.

compiler/term_pass1.m:
	Use the new traversal module.

	Clarify the fixpoint computation on the set of output supplier
	arguments.

	Remove duplicates from the list of equations given to the solver.
	This avoids a det stack overflow in lp.m when doing termination
	analysis on options.m.

	If an output argument of a predicate makes sense only in the absence
	of errors, then return it only in the absence of errors.

compiler/term_pass2.m:
	Use the new traversal module. Unlike the previous code, this allows us
	to ignore recursive calls with input arguments bigger than the head
	if those calls occur after goals that cannot succeed (since those
	calls will never be reached).

	Implement a better way of doing single argument analysis, which
	(unlike the previous version) works in the presence of mutual recursion
	and other calls between the recursive call and the start of the clause.

	Implement a more precise way of checking for recursions that don't
	cause termination problems. We now allow calls from p to q in which
	the recursive input supplier arguments can grow, provided that on
	any path on which q can call p, directly or indirectly, the recursive
	input supplier arguments shrink by a greater amount.

	If an output argument of a predicate makes sense only in the absence
	of errors, then return it only in the absence of errors.

compiler/term_util.m:
	Updates to reflect the changes to the representation of termination
	information.

	Reorder to put related code together.

	Change the interface of several predicates to better reflect the
	way they are used.

	Add some more utility predicates.

compiler/term_errors.m:
	Small changes to the set of possible errors, and major changes in
	the way the messages are printed out (we now use error_util).

compiler/options.m:
	Change --term-single-arg from being a bool to an int option,
	whose value indicates the maximum size of an SCC in which we try
	single argument analysis. (Large SCCs can cause single-arg analysis
	to require a lot of iterations.)

	Add an (int) option that controls the max number of paths
	that we are willing to analyze (analyzing too many paths can cause
	det stack overflow).

	Add an (int) option that controls the max number of causes of
	nontermination that we print out.

compiler/hlds_pred.m:
	Use two separate slots in the proc_info to hold argument size data
	and termination info, instead of the single slot used until now.
	The two kinds of information are produced and used separately.

	Make the layout of the get and set procedures for proc_infos more
	regular, to facilitate later updates.

	The procedures proc_info_{,set_}variables did the same work as
	proc_info_{,set_}varset. To eliminate potential confusion, I
	removed the first set.

compiler/*.m:
	Change proc_info_{,set_}variables to proc_info_{,set_}varset.

compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
	Change the code to handle the arg size data and the termination
	info separately.

compiler/prog_data.m:
	Change the internal representation of termination_info pragmas to
	hold the arg size data and the termination info separately.

compiler/prog_io_pragma.m:
	Change the external representation of termination_info pragmas to
	group the arg size data together with the output supplier data,
	to which it is logically connected.

compiler/module_qual.m:
compiler/modules.m:
	Change the code to accommodate the change to the internal
	representation of termination_info pragmas.

compiler/notes/compiler_design.html:
	Fix some documentation rot, and clarify some points.

	Document termination analysis.

doc/user_guide.texi:
	Document --term-single-arg and the new options.

	Remove spaces from the ends of lines.

library/bag.m:
	Add a new predicate, bag__least_upper_bound.

	Fix code that would do the wrong thing if executed by Prolog.

	Remove spaces from the ends of lines.

library/list.m:
	Add a new predicate, list__take_upto.

library/set{,_ordlist}.m:
	Add a new predicate, set{,_ordlist}__count.

tests/term/*:
	A bunch of new test cases to test the behaviour of termination
	analysis. They are the small benchmark suite from our paper.

tests/Mmakefile:
	Enable the new test case directory.
1997-12-22 10:01:33 +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
1acfdbff07 Add support for a new `GRADEFLAGS' variable to Mmake,
Estimated hours taken: 1

Add support for a new `GRADEFLAGS' variable to Mmake,
so that you can use the more readable (and more portable)
`GRADEFLAGS = --profiling' rather than e.g. `GRADEFLAGS = asm_fast.gc.prof'.

scripts/Mmake.vars.in:
	Add GRADEFLAGS variable, defaulting to `--grade $(GRADE)'.

scripts/Mmake.rules:
	Change various rules to use `$(GRADEFLAGS)' instead of
	`--grade $(GRADE)'.

compiler/modules.m:
	Change various rules in the generated `.dep' files to
	use `$(GRADEFLAGS)' instead of `--grade $(GRADE)'.

doc/user_guide.texi:
	Modify the documentation to reflect the above changes.
1997-11-21 08:08:32 +00:00
Simon Taylor
c969967e24 Added option --generate-module-order which writes the module dependency
Estimated hours taken: 1

Added option --generate-module-order which writes the module dependency
ordering to <module>.order during dependency generation. This is expected
to be useful for improving the effectiveness of termination analysis.

compiler/options.m
compiler/handle_options.m
        Added option --generate-module-order.

compiler/modules.m
        Compute and print out the ordering.

doc/user_guide.texi
        Document --generate-module-order.
1997-10-16 04:59:52 +00:00
Christopher Rodd Speirs
f9ad85698a Add termination analysis to the compiler. The termination analysis
Estimated hours taken: 500

Add termination analysis to the compiler. The termination analysis
annotates each procinfo structure with termination information stating
whether each procedure is guaranteed to terminate.
Add transitive intermodule optimization to the compiler. Transitive
intermodule optimization uses .trans_opt files to store optimization
information.  The difference between .trans_opt files and .opt files is
that .trans_opt files may depend on other .trans_opt files, whereas .opt
files may only depend on a .m file.

compiler/termination.m:
	New file.  The main module which controls the termination
	analysis.
compiler/term_pass1.m:
	New file.  This file implements the first pass of the
	termination analysis which attempts to derive relationships
	between the relative sizes of variables.  This information is
	used by term_pass2.m
compiler/term_pass2.m:
	New file.  The second pass of the termination analysis attempts
	to prove that each predicate or function in the program is
	guaranteed to terminate.
compiler/term_util.m:
	New file.  Contains utilities which are used in various stages
	of the termination analysis.
compiler/term_errors.m:
	New file.  Contains predicates for printing out error messages
	produced by termination analysis.
compiler/trans_opt.m:
	New file.  This module contains predicates for both reading in
	and writing .trans_opt files.
compiler/globals.m:
compiler/handle_options.m:
compiler/options.m:
	Various modifications to handle the new options.  Some of the
	new options imply other options, and the `--termination-norm'
	option is a string option which needs processing.
compiler/hlds_goal.m:
	Added a comment that the list(uni_mode) subfield of construct,
	and the unify_mode subfield of unify are not necessarily valid
	when the unification applies to higher order terms.
compiler/hlds_out.m:
	Added code to output termination information, as well as code to
	print out the new markers.
compiler/hlds_pred.m:
	Added the termination subfield to the proc_info structure and
	added code to support it.  Also added support for the new
	markers.
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/prog_io_pragma.m:
	Added support for the new pragmas, `termination_info',
	`teminates', `check_termination' and `does_not_terminate'.
compiler/prog_data.m:
	Added the new pragmas to the pragma_type.  Also reformatted the
	type declarations to conform with the coding specifications.
compiler/prog_io.m:
	Reformatted some code and comments.
compiler/mercury_compiler.m:
	Added code to call the termination analyser and to call the
	predicate which creates .trans_opt files.
doc/reference_manual.texi:
	Documented the termination analysis and the new pragmas.
doc/user_guide.texi:
	Documented the new options.
1997-10-09 09:39:41 +00:00
Fergus Henderson
b3b910d75a Change the generated `.dep' file so that the rule for making shared
Estimated hours taken: 0.25

compiler/modules.m:
	Change the generated `.dep' file so that the rule for making shared
	libraries passes `--grade $(GRADE)' to `ml --make-shared-lib'.
	Otherwise creation of shared libraries in non-standard grades
	such as `asm_fast.gc.tr' won't work.
1997-09-14 05:03:33 +00:00
Fergus Henderson
99184d3578 Implement support for types with user-defined equality predicates.
Estimated hours taken: 30

Implement support for types with user-defined equality predicates.

Types with user-defined equality predicates are called "non-canonical types";
they may have more than one representation for the same abstract value.
That means that any attempt to deconstruct a value of a non-canonical
type, i.e. any attempt to peek at the representation, must be cc_multi.

This also implies that conceptually speaking, non-canonical types are not
members of the type classes `comparable' (compare/3) or `deconstructible'
(index/2, argument/3, functor/3, deconstruct/5).  Since we don't support
type classes yet, that just means that the type-class checking is done
at runtime, i.e. any call to one of those functions for a non-canonical
type will call error/1 or fatal_error().

To make non-canonical types useful, we really need type classes,
so that the user can provide instance definitions for `comparable'
and `deconstructible' for such types.  It might also be a good idea
to have a type-class `canonicalizable' which provides a function
to convert its argument to some canonical type (that would
require existential types to do nicely, but alternatively we could
just use `univ').

Note that currently the only mechanism for promising that things are
unique is via the C interface.

compiler/det_analysis.m:
	Add code to check unifications that examine the
	representation of a type with a user-defined equality predicate.
	Any such unification must occur in a single-solution context and
	must not be able to fail.  Such unifications determinism have
	determinism cc_multi.

compiler/det_report.m:
	Add code to report errors for misuse of types with user-defined
	equality predicates.  (Also some other stylistic improvements:
	split up a complicated predicate into subroutines, and
	avoid some unnecessary code duplication.)

compiler/prog_data.m:
compiler/hlds_data.m:
	Add a new `maybe(sym_name)' field to the du_type/3 constructor
	to hold the name of the user-defined equality pred for the
	type, if any.

compiler/prog_io.m:
	Add code to parse the new `... where equality is <name>.' syntax.
	Delete the old support for `... where <condition>'.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/mercury_to_goedel.m:
	Print out the new field.

compiler/base_type_layout.m:
compiler/code_util.m:
compiler/dense_switch.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/make_hlds.m:
compiler/mode_util.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/switch_detection.m:
compiler/tag_switch.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
	Trivial changes to ignore (or leave unchanged)
	the new field in `du_type'.

compiler/modecheck_unify.m:
	Pass the term__context to unify_proc__request_unify.

compiler/typecheck.m:
	Typecheck the compiler-generated unify predicates for types
	with user-defined equality preds.

compiler/unify_proc.m:
	For d.u. types, if the type has a user-defined equality predicate
	then generate code for the compiler-generated unify predicate
	that just calls the specified predicate, and generate
	code for the compiler-generated compare and index predicates
	that just calls some procedures in mercury_builtin.m that
	report appropriate error messages.
	Ensure that the automatically-generated predicates
	have appropriate term__contexts everywhere, so that if
	the user-defined equality predicate name is ambiguous,
	non-existent, or has the wrong type, mode, or determinism,
	then the error messages from type checking, mode checking,
	or determinism checking refer to the type declaration.

library/mercury_builtin.m:
	Add predicates builtin_index_non_canonical_type/2
	and builtin_compare_non_canonical_type/2, used by
	the code generated by compiler/unify_proc.m.

doc/reference_manual.texi:
	Document the support for user-defined equality predicates.

library/std_util.m:
	Change ML_expand() to return an indication of whether or not
	the type is a non-canonical type (one with a user-defined
	equality predicate).  Change argument/2, functor/2, and
	deconstruct/4 to abort if called for a non-canonical type.
1997-08-22 13:57:43 +00:00
Zoltan Somogyi
516c58709e Fix spelling error in comment.
Estimated hours taken: 0.01

modules:
	Fix spelling error in comment.
1997-08-06 04:40:26 +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
Fergus Henderson
3a2a10c193 Simplify the process for creating and using Mercury libraries,
and document it.

compiler/modules.m:
	Add rules for creating the `.a', `.so', and `.init' files.
	The `.so' file is creating using ml's new `--make-shared-lib' option.

scripts/Mmake.vars.in:
	Add definitions for AR, ARFLAGS, RANLIB, and RANLIBFLAGS,
	for use by the new rules generated in `.dep' files by modules.m.

Mmake.common.in:
	Remove RANLIB, since it's now defined in scripts/Mmake.vars.in.

doc/user_guide.texi:
	Add a chapter on libraries.
1997-07-15 09:12:01 +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
Tyson Dowd
f9674e6fb8 Remove references to .garb files.
Estimated hours taken: 0.5

compiler/modules.m:
scripts/Mmake.rules:
	Remove references to .garb files.
	We are not going to use a separate link phase for accurate gc
	anymore.
1997-06-03 07:01:10 +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
David Overton
b043b3e880 Implemented `:- pragma fact_table' for string, int and float
Estimated hours taken: 250

Implemented `:- pragma fact_table' for string, int and float
argument types.  Facts can have any combination of input and output modes.
Hash tables are used to lookup facts in modes that have input
arguments.

compiler/fact_table.m:
	Added code for outputting `pragma c_code' to access facts in all
	mode/determinism combinations in `pragma fact_table's.
	Added code to build and output hash tables (as C arrays) for
	input modes of fact tables.
	Many other changes and rearrangements in the module to support the
	above.

compiler/export.m:
	Moved declarations for `convert_type_from_mercury/3' and
	`convert_type_to_mercury/3' to the interface so they can be
	used by `fact_table.m'.

compiler/handle_options.m:
	Add a check to `postprocess_options' to ensure that arguments
	to `--fact-table-hash-percent-full' are integers in the range
	1 to 100.

compiler/inlining.m:
	Stop `model_non' `pragma c_code' being inlined unless it has
	the new `extra_pragma_info' field (which hasn't been fully
	implemented yet).  This ensures that code such as the lookup
	code generated for nondet and multidet modes of `pragma
	fact_table's works with inlining turned on.

compiler/make_hlds.m:
	Added arguments to the calls to predicates in fact_table.m
	where necessary.
	Add `c_header_code' returned by `fact_table_compile_facts' to
	the module_info.

compiler/mode_util.m:
	Added two new predicates:
	`mode_is_fully_input' which is true iff the initial
		inst of the mode is ground.
	`mode_is_fully_output' which is true iff the inital inst is
		free and the final inst is ground.

compiler/modules.m:
	Added a dependency to `.d' files to ensure that fact table C
	files are recompiled whenever they are recreated.

compiler/options.m
	Added new options:
		`--fact_table_max_array_size <n>' where n is the
			maximum size array to use for `pragma fact_table'
			data.  (default 1024)
		`--fact_table_hash_percent_full <n>' where n is how
			full the `pragma fact_table' hash tables should
			be allowed to get, given as an integer percentage
			(between 1 and 99).  (default 90).
	Documentation for these options has been added to the usage
	message but is commented out at the moment.
1997-02-28 05:30:41 +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
David Overton
89ffc9a93a Changes to automatic dependency generation to allow parallel make to
Estimated hours taken: 0.5

Changes to automatic dependency generation to allow parallel make to
work with modules containing `pragma fact_table's and to add fact
table C files to the list of files deleted by `mmake clean' and
`mmake realclean'.

compiler/modules.m:
        In `.dep' files: add the C file produced by
                `:- pragma fact_table' to the list of <main_module>.cs so it
                is deleted by `mmake clean' and `mmake realclean'.
        in `.d' files: add a dependency to stop the fact table C file
                from being compiled before it is created by
                `mercury_compile'.  This allows parallel make (i.e.  `-j<n>')
                to work properly.
1997-02-16 23:48:59 +00:00
Fergus Henderson
4c90d2cab6 Fix a bug: modules.m was calling globals__io_lookup_bool_option
Estimated hours taken: 0.45

Fix a bug: modules.m was calling globals__io_lookup_bool_option
with `inhibit_warnings', but the type of `inhibit_warnings'
had been changed from `bool' to `bool_special', hence the
lookup failed with a runtime error.

compiler/modules.m:
	Use `warn_simple_code' rather than `inhibit_warnings' when
	checking whether to warn about "module imports itself".
1997-01-31 17:50:14 +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
Fergus Henderson
ff387d9691 Fix a bug that Tyson reintroduced during CVS merging about six months ago,
Estimated hours taken: 1

Fix a bug that Tyson reintroduced during CVS merging about six months ago,
which caused the `.d' files created by `mc --generate-dependencies'
to include unnecessary dependencies, sometimes resulting in
unnecessary recompilation.

compiler/modules.m:
	Fix a couple of cases of passing arguments in the wrong order.

	(Also, put `mercury_builtin' in the interface dependencies,
	not just the implementation dependencies.)
1997-01-25 13:05:45 +00:00
Simon Taylor
bb2b816787 * Inter-module unused argument removal.
Estimated hours taken: 100

* Inter-module unused argument removal.

* Allow the user to specify which directories should be searched
for .opt files.

* Enhancements to simplify.m and common.m which will be useful for
partial deduction.

compiler/options.m
	Added and documented options:
	--intermod-unused-args to enable inter-module unused argument removal.
	--intermod-directory <dir>, same as --search-directory except used
		to locate .opt files.
	--use-search-directories-for-intermod - use the search directories
		for .opt files as well.
	--warn-simple-code - a flag to control the warnings produced by
		simplify.m so that they respect --inhibit-warnings.

compiler/unused_args.m
	Use the unused argument info from the .opt file.
	Clobber the dependency_info if any new preds were added.

compiler/hlds_module.m
	Added a field to the module_info to store unused argument
	information from .opt files.

compiler/prog_data.m
	Add :- pragma unused_args to hold unused argument information.
	This should only be used in .opt files.

compiler/make_hlds.m
	Build the unused_arg_info field in the module_info.
	Check that pragma unused_args only appears in .opt files.
	Fill in the non-locals field in the goal_info for the builtin
	stubs so that mode analysis computes the correct instmap delta.

compiler/intermod.m
	Read in the unused argument information for the current module when
	compiling to C. This is used to ensure that clauses are produced with
	the correct number of removed arguments (it may be possible to remove
	more arguments with the information from other modules).
	Fix a bug in the handling of module qualified function calls and
	higher-order predicate constants.

compiler/handle_options.m
	Handle --intermod-unused-args and
	--use-search-directories-for-intermod.

compiler/mercury_compile.m
	Run the entire front end and polymorphism (not just up to
	typechecking) when building the .opt file with
	--intermod-unused-args.
	Use the new interface to simplify.m, remove calls to excess.m
	and common.m.

compiler/code_util.m
compiler/llds_out.m
	When generating local code for a specialized version of a predicate
	from another module, put this module's name on the label to avoid
	link errors.

compiler/higher_order.m
	Don't add the originating module name to the name of the specialized
	version, since that is now done in code_util.m.
	Clobber the dependency graph so that inlining will work on the
	specialized versions in profiling grades (this will cause slightly
	slower compilation in profiling grades, something I need to fix).

compiler/simplify.m
	Merge a branching goal and an adjacent switch where the branches
	of the first goal contain extra information about the switched
	on variable of the second goal.
	Merge the excess assignments and common subexpression elimination
	passes into simplify.m.

compiler/excess.m
	The functionality of this module is now in simplify.m, but I'll
	leave it here for now.

compiler/instmap.m
	Added predicates instmap__bind_var_to_functor and
	instmap_delta_bind_var_functor to which take a var, cons_id
	and an instmap and adjust the inst of the var. This is used to
	update the instmap at the beginning of each case in a switch.
	Fix a bug in merge_instmap_delta where variables whose inst had
	information added in one branch of a switch, disj, or ite had that
	changed inst included in the instmap_delta for the entire
	branched goal.

compiler/mode_util.m
	Use instmap_delta_bind_var_to_functor in recompute_instmap_delta.
	Added predicate bind_inst_to_functor which takes a ground or bound
	inst and a cons_id and adjusts the top level of the inst to be bound
	to that cons_id. Other types of inst are left unchanged.
	Change recompute_instmap_delta so that the switched on variable of
	a switch is bound to the functor in each case even if the binding
	unification has been removed. Added a boolean argument to request
	recomputation of instmap_deltas for atomic goals.

compiler/modes.m
compiler/unique_modes.m
	Make sure that the instmap_delta for each branch of a switch
	includes the extra information added by the functor test.

compiler/common.m
	Removed the goal traversal. Leave preds to be called by simplify.m
	to optimise common unifications and calls.
	Warn about and eliminate multiple calls to a predicate with the same
	input arguments.
	Replace deconstructions of known terms with assignments to the output
	variables where this would not make more variables live at stack
	flushes.

compiler/follow_code.m
	Exported move_follow_code_select.
	Don't move follow code into erroneous branches.

library/string.nu.nl
	Added string__contains_char/2.

compiler/base_type_layout.m
compiler/special_pred.m
compiler/vn_order.m
library/mercury_builtin.m
	Removed duplicate calls.

doc/user_guide.texi
	Documented options.

tests/warnings/duplicate_call.m
tests/warnings/duplicate_call.exp
	Test duplicate call warning.
1997-01-20 03:27:59 +00:00
Fergus Henderson
27a59bdf03 Fix a bug reported by Tom.
Estimated hours taken: 0.5

Fix a bug reported by Tom.

modules.m:
	If a module interface contains a pragma declaration
	other than `pragma obsolete', then issue a warning
	and ignore the pragma when creating the interface file.
1996-12-20 20:08:48 +00:00
David Overton
37c5340f1c Added code to various sections of the compiler to parse
Estimated hours taken: 80

Added code to various sections of the compiler to parse
`pragma fact_table' declarations and add them to the HLDS.

Added output of fact_table dependencies to .d and .dep files.

Added a new module fact_table.m for parsing the actual fact tables and
generating code.  This is not finished yet.

Added ability to have `pragma c_code' declarations for Mercury
functions.

Modified Files:
   compiler/hlds_module.m
	Added predicate `module_info_set_pred_info' to add a `pred_info'
	entry to `module_info' given a `pred_id'.

   compiler/make_hlds.m
	Added code to handle new `pragma fact_table' declarations.
	New predicate `module_add_pragma_fact_table' which calls the
	fact compiler in fact_table.m to compile the fact table and
	generate C code to access it.  Then add the C code to the HLDS
	as a `pragma c_code'.

	Mercury functions can now have `pragma c_code' declarations.

   compiler/intermod.m
   	Included PredOrFunc argument in call to mercury_output_pragma_c_code.

   compiler/mercury_compile.m
	Added parameters to some predicates to allow fact table
	dependency information to be passed around.

   compiler/mercury_to_mercury.m
   	Handle output of `pragma fact_table' declarations.
	Handle output of `pragma c_code' declarations for functions.

   compiler/module_qual.m
   	Handle module qualification of `pragma fact_table'
	declarations.

   compiler/modules.m
   	New predicate `get_fact_table_dependencies' to work out which
	fact tables a module depends on.
	Changes to `write_dependency_file' to write out fact table
	dependencies.
	Changes to some other predicates to allow fact table
	dependencies to be passed around the module.

   compiler/prog_data.m
   	Added new functor `fact_table(sym_name, arity, string)'
	to the `pragma_type' type.
	Added a `pred_or_func' field to the `c_code' functor of the
	`pragma_type' type.

   compiler/prog_io.m
   	Added code to `parse_pragma_type' to parse `:- pragma fact_table'.
	Here is a sample declaration.  The facts are in a file called
	"factfile":

	:- pred facts(string, int, float).
	:- mode facts(out, out, out) is multidet.
	:- pragma fact_table(facts/3, "factfile").

	Mercury functions can now have `pragma c_code' declarations.
	Here is a sample declaration:

	:- func c_add(int, int) = int.
	:- pragma c_code(non_recursive, c_add(A::in, B::in) = (C::out), "
		C = A + B;
		").


Added Files:
   compiler/fact_table.m
   	Module not yet finished, but it compiles correctly and doesn't
	interfere with the rest of the compiler.

	Main purposes of the module are to parse the fact table
	file, perform type, mode and determinism checks and generate C
	code for the fact table.

	Completed so far:  parsing, type and mode checking,
	determinism inference.  A C array is output to represent the
	table, but no functions are produced yet to access it.
1996-12-17 23:40:31 +00:00
Fergus Henderson
25199123e9 Change the code to stop it outputting one unnecessary space in
Estimated hours taken: 0.1

compiler/modules.m:
	Change the code to stop it outputting one unnecessary space in
	the `.dep' files.
1996-12-12 11:55:15 +00:00
Fergus Henderson
d83c1c4f58 Fix a typo in the code to write out the `.dep' file
Estimated hours taken: 0.25

modules.m:
	Fix a typo in the code to write out the `.dep' file
	that broke `mmake foo.opts'.
	Also fix a capitalisation error in one of the warning messages.
1996-11-24 23:48:15 +00:00
Zoltan Somogyi
e9cbb5c329 Add a new option, --assume-gmake. Rename the existing option
Estimated hours taken: 5

options:
	Add a new option, --assume-gmake. Rename the existing option
	--optimize-constructor-recursion to --optimize-constructor-last-call,
	since it also affects last calls that are not recursive calls.

modules.m
	If --assume-gmake is set, exploit the capabilities of gmake
	to produce significantly smaller .dep files (about 10% the size
	of the ones we produced before for mercury_compile).

mercury_compile:
	Change --optimize-constructor-recursion to
	--optimize-constructor-last-call.

hlds_out:
	Clean up the way we produce HLDS dumps. The new algorithm eliminates
	lines containing nothing but white space or a single comma or dot
	in procedure definitions. It should also be easier to modify.

constraint, mode_errors:
	Use the new interface of a predicate in hlds_out.

livemap:
	Make a predicate more self-contained.
1996-11-21 08:38:39 +00:00