Commit Graph

49 Commits

Author SHA1 Message Date
Thomas Conway
a70b59e83c Add a test to find the number of words needed to represent a
configure.in:
        Add a test to find the number of words needed to represent a
        synchronization term.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

runtime/mercury_engine.h:
        declare the mercury_engine structure.

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

scripts/init_grade_options.sh-subr
        add thread_safe

scripts/mgnuc.in
        add THREAD_OPTS

scripts/ml.in:
        add THREAD_LIBS
1998-06-09 02:16:31 +00:00
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
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
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
Andrew Bromage
513132f8a8 Better error reporting for variables bound in illegal places.
Estimated hours taken: 2

Better error reporting for variables bound in illegal places.

compiler/mode_info.m:
	Add a var_lock_reason, specifying the reason why a variable
	is locked during mode checking.

compiler/modecheck_unify.m:
compiler/modes.m:
compiler/unique_modes.m:
	Specify the reason when locking some variables.

compiler/mode_errors.m:
	When reporting var locking errors, give the reason why the
	var was locked.

tests/invalid/Mmakefile:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/bind_var_errors.m:
	Regression tests for the above changes.
1998-01-30 06:13:35 +00:00
Zoltan Somogyi
5013dd9c76 Implement nondet pragma C codes.
Estimated hours taken: 40

Implement nondet pragma C codes.

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

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

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

	Fix the indentation in some places.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

compiler/*.m:
	Minor changes to conform to changes to the HLDS and LLDS data
	structures.
1998-01-13 10:14:23 +00:00
Fergus Henderson
0b337ee174 Handle inference of mostly-unique (not just unique) modes.
Estimated hours taken: 25

Handle inference of mostly-unique (not just unique) modes.

compiler/unique_modes.m:
	Change the handling of calls so that if the mode originally selected
	by ordinary mode analysis (modes.m) won't work, then it now calls
	modecheck_call_pred to introduce a new mode for the predicate.

compiler/unify_proc.m:
	Generalize the existing "unify request queue" so that
	it can handle requests for any kind of predicate, not
	just for unification predicates, and hence rename the
	`unify_request' table which contains it as the `proc_request' table.

compiler/hlds_module.m:
	Rename the `unify_request' table as the `proc_request' table.

compiler/modecheck_call.m:
	When introducing new modes for predicates, do this by adding them
	to the request queue.  This ensures that when we do get around
	to processing predicates added in unique mode analysis, we will
	run mode analysis, switch detection, and determinism analysis
	before doing unique mode analysis.  To make this work, we
	need to pass down a `maybe(determinism)' argument indicating
	the determinism of the newly added procedure.  unique_modes.m
	sets this to the determinism inferred for the mode originally
	inferred by modes.m.  That should be OK, because uniqueness
	should not affect determinism.
	Also change modecheck_call_proc to return a `Changed' flag
	indicating whether we need to rerun fixpoint analysis.
	And change `get_var_insts_and_lives' to return `dead' for
	mostly_unique modes, not just for unique modes, so that
	we can infer `mdi' modes.

compiler/modes.m:
	Instead of analyzing everything to a fixpoint, and then
	analyzing the queued unification procedures, change it so
	that analysis of queued procedures is part of each fixpoint
	iteration.
	When doing ordinary mode analysis for calls, pass `no' as the
	new `maybe(determinism)' argument to modecheck_call_pred.

compiler/constraint.m:
compiler/cse_detection.m:
	Ignore the new output argument for modecheck_call_proc.

compiler/mode_util.m:
	Add code to insts_to_mode to recognize `muo', `mui', and `mdi'
	modes and use the corresponding abbreviations (previously this
	was done only for `uo', `ui', `di', `in' and `out').

tests/valid/mostly_uniq_mode_inf.m:
	A test case for the above change.
1998-01-05 07:26:32 +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
9fc30fa8bb Change unique mode analysis (unique_modes.m) so that it does the same
Estimated hours taken: 4

Change unique mode analysis (unique_modes.m) so that it does the same
fixpoint analysis that ordinary mode analysis (modes.m) does.

This is a first step towards mode inference of "mostly-unique" modes.
Unique mode analysis still won't introduce any new modes, but it may
now change the final insts of inferred modes from `unique' to `mostly_unique'.

The next step (not included in this diff) will be to change the handling of
calls in unique_modes.m so that it does introduce new modes.

Also change things so that the inferred modes are normally printed
only after unique mode analysis, with determinism annotations attached.

compiler/modes.m:
	Add an extra WhatToCheck parameter to lots of predicates,
	so they can also be used for checking unique modes.
	Add a few small new bits of code to handle the
	`WhatToCheck = check_unique_modes' case.

compiler/unique_modes.m:
	Call the routines in modes.m rather than special casing things.
	The checking of goals is still special-cased, since for
	example unique_modes does not do reordering, but the traversal
	of modules and procedures now uses code from modes.m.

compiler/mode_errors.m:
	Add an extra bool parameter to write_mode_inference_messages
	indicating whether or not to print determinism annotations.

tests/valid/Mmakefile:
tests/valid/mostly_uniq_mode_inf.m:
	Test case for the above change.
1997-11-24 23:10:38 +00:00
Fergus Henderson
56661add6b Fix a bug in the handling of implied modes.
Estimated hours taken: 10

Fix a bug in the handling of implied modes.

compiler/modes.m:
	Change the representation of extra_goals from just a pair
	of lists of goals (goals to insert before & after the main
	goal, respectively) so that it includes an instmap, which
	is the instmap after the main goal.  This change is required
	because without it it was incorrectly computing the instmap
	delta for the main goal, if the after-goals list was non-empty.
	Also, delete the before-goals list, because it is not used
	and because getting the instmap deltas right for before-goals
	would be tricky.

compiler/modecheck_unify.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
	Various changes to use the new representation of extra_goals.

tests/hard_coded/Mmake:
tests/hard_coded/impossible_unify.m:
tests/hard_coded/impossible_unify.exp:
	Regression test for the above-mentioned bug.
1997-09-15 21:12:50 +00:00
Fergus Henderson
5976f769f7 Fix a bug for the case of a higher-order function call in code
Estimated hours taken: 1

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

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

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

tests/valid/Mmake:
tests/valid/ho_func_call.m:
	Regression test for the above-mentioned bug.
1997-09-01 14:05:44 +00:00
Fergus Henderson
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
Andrew Bromage
9b7f11c6dd Reorganisation of modules to do with the inst data type.
Estimated hours taken: 20

Reorganisation of modules to do with the inst data type.

This is actually the first installment of the alias tracking mode
checker in disguise.  A very good disguise.  The rationale for
this reorganisation is to reduce coupling in the part of the mode
checker which is _not_ in this change (ie most of it).

Alias tracking requires a new kind of inst, alias(inst_key), where
an inst_key is a handle on some other sub-inst.  With it goes a
data structure in which to store dereferenced insts and all the
operations which go with it.  This code will go in the new module
inst.m so that it doesn't have to go in prog_data.m.  (I briefly
considered putting it in instmap.m however this introduces some
bad coupling since instmap.m imports hlds_module.m.  Putting it
in prog_data.m would cause hlds_*.m to depend on prog_data.m,
but we have designed things so that the dependencies go in the
other direction.)

The remainder of the reorganisation is a general cleanup: the
inst testing predicates (inst_is_*) have been moved out of
mode_util because they are not actually operations on modes at
all, and have been moved into inst_match.  inst_match has then
been split because otherwise it would be 2000 lines long and
will get significantly bigger when aliasing is added.  Roughly
speaking, any operations which create new insts from old ones
have been moved into a new module, inst_util while any operations
which test the values of insts remain in inst_match.

Also included are the removal of some NU-Prologisms since the
NU-Prolog version of the compiler is no longer supported.  Two
changes here:

	- Removal of some when declarations.
	- A gross hack in inst_is_*_2, where two copies of
	  the same inst were passed into the predicate so that
	  one could be switched on.  Thank NU-Prolog's lack of
	  common subexpression elimination.

compiler/inst.m:
	New module which contains the data types inst, uniqueness,
	pred_inst_info, bound_inst.

compiler/inst_util.m:
	New module which contains predicates which perform mode
	checking-like operations on insts.

	Moved in:
		abstractly_unify_inst, abstractly_unify_inst_functor,
		inst_merge, make_mostly_uniq_inst (from inst_match.m)

compiler/inst_match.m:
	Moved out:
		inst_merge, make_mostly_uniq_inst,
		abstractly_unify_inst, abstractly_unify_inst_functor
			(to inst_util.m)

	Moved in:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(from mode_util.m)

	Now exported:
		unique_matches_initial/2, unique_matches_final/2
		inst_contains_instname/3, pred_inst_matches/3
		(They are required by inst_util.m, and they are
		useful in their own right.)

compiler/instmap.m:
	instmap_delta_lookup_var/3 reincarnated as
	instmap_delta_search_var/3.  The reason for this change is
	that previously, instmap_delta_lookup_var simply returned
	`free' if the searched-for var did not occur in the
	instmap_delta.  This is somewhat non-obvious behaviour.
	instmap_delta_search_var/3 fails in such a situation.

compiler/mode_util.m:
	Moved out:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(to inst_match.m)
		(These are not really operations on modes.)

compiler/modecheck_call.m:
	Moved in modecheck_higher_order_func_call/5, from modecheck_unify.m

compiler/modecheck_unify.m:
	Moved out modecheck_higher_order_func_call/5, to modecheck_call.m
	where it should have been all along.

compiler/prog_data.m:
	Moved out the types inst, uniqueness, pred_inst_info,
	bound_inst (to inst.m).

compiler/common.m:
compiler/cse_detection.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/liveness.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_util.m:
compiler/simplify.m:
compiler/switch_detection.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
	Miscellaneous minor changes to cope with the above changes.

compiler/notes/compiler_design.html:
	Document the new modules.
1997-07-24 01:27:21 +00:00
Fergus Henderson
e3471f333f Fix a bug in inlining of polymorphic pragma c_code procedures.
Estimated hours taken: 3

Fix a bug in inlining of polymorphic pragma c_code procedures.

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

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

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

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

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

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

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

compiler/live_vars.m:
	Comment out some code to avoid a warning about `fail'
	in the condition of an if-then-else.
1997-05-05 11:17:40 +00:00
Simon Taylor
5609982aa5 Fix an abort and a duplicate warning message problem.
Estimated hours taken: 4

Fix an abort and a duplicate warning message problem.

compiler/det_report.m
        Replace the goals and goal_infos from the type det_msg,
        and replace them with the contexts of the goals. This ensures
        that the det_msg for a particular construct is unique, even
        if goal is changed and simplification is rerun on the goal.

compiler/simplify.m
        Fix and enable the code to optimize if-then-elses that cannot
        succeed.
        Stop warnings appearing multiple times.
        Produce warnings for all cases of a negated goal not succeeding
        or failing, not just \+ true and \+ fail.

compiler/liveness.m
        Fix a bug in the liveness annotations for if-then-elses which cannot
        succeed. Since simplify.m now optimizes away all such if-then-elses,
        this change isn't really necessary, but may prevent the bug
        reappearing in future.

compiler/modes.m
        Remove code to optimize if-then-elses with conditions that cannot
        succeed, since that is now done in simplify.m. Also the code
        here was buggy, in that it set the instmap_delta of the negated
        condition to reachable, even if the condition's determinism turned
        out to be erroneous. This couldn't be fixed easily, because
        determinism information is not available in modes.m

compiler/unique_modes.m
        Removed the commented out version of the if-then-else optimization
        removed from mode analysis.

tests/warnings/simple_code.{m, exp}
        Test cases for the warnings from simplify.m

tests/valid/fail_ite.m
        Regression test for the abort.
1997-04-28 00:02:09 +00:00
Simon Taylor
14bc9b8f70 Bug fixes for module qualified cons_ids.
Estimated hours: 8

Bug fixes for module qualified cons_ids.

Improve the compilation time of modules with lots of user_defined insts.
(Compilation of tree234.m with the unique tree skeleton modes enabled is
still way too slow).

compiler/mode_util.m
	In propagate_type_info_into_modes and the predicates it calls, avoid
	finding the constructors for a type and substituting the argument
	types.

compiler/hlds_pred.m
	Add a new field to the proc_info, maybe_declared_argmodes which
	holds the declared arg_modes for use in .opt files and error messages.

compiler/typecheck.m
	Call propagate_type_info_into_modes from here to avoid calling it
	many times throughout mode analysis. This does not cause a
	substantial performance improvement, but reduces confusion
	over where everything should be module qualified.
	This also fixes a bug with the no_tag optimisation reported by
	Mark Brown. A runtime abort occurred because a constructor in a bound
	inst was not being module qualified which confused mode_to_arg_mode
	into giving the argument an arg_mode of top_unused.

compiler/modecheck_unify.m
	Call propagate_type_info_mode_list for modes of lambda predicates.

compiler/modes.m
compiler/modecheck_call.m
compiler/unique_modes.m
	Don't call propagate_type_info_mode_list since that has
	already been done in typecheck.m.

compiler/intermod.m
	Write out the declared arg_modes, since these don't contain
	constructs such $typed_inst which the parser doesn't handle.

compiler/clause_to_proc.m
compiler/unify_proc.m
	Fill in the declared_argmodes field in proc_infos.

compiler/type_util.m
	Avoid creating the substitution multiple times in type_constructors.

compiler/mercury_compile.m
	Added some documentation.

tests/hard_coded/Mmake
tests/hard_coded/imported_no_tag.m
tests/hard_coded/test_imported_no_tag.m
tests/hard_coded/test_imported_no_tag.exp
	Add Mark Brown's test case.
1997-04-08 02:26:43 +00:00
Zoltan Somogyi
34b86aac8d Move a two-line block of code so that they are executed
Estimated hours taken: 0.5

unique_modes:
	Move a two-line block of code so that they are executed
	before some other code that depends on their output in the
	SICStus version of the compiler as well as the Mercury version.
1997-03-18 07:18:06 +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
Simon Taylor
1839ebb663 Module qualification of constructors.
Estimated hours taken: 15

Module qualification of constructors.

compiler/modes.m
compiler/unique_modes.m
compiler/modecheck_unify.m
compiler/modecheck_call.m
	Enable propagate_type_info_into_modes.
	Use type information to module qualify cons_ids.

compiler/mode_util.m
	Use propagate_type_information_into_modes to module qualify cons_ids
	in bound insts.
	typed_ground/2 and free/1 insts are not yet generated, since they
	are not yet used anywhere.
	Avoid expanding insts when propagating type information, since
	that is not yet useful.
	I still need to fix the handling of
		inst_matches_{initial, final, binding}(
			ground(_, _), bound(_, [all_functors_in_the_type]))

compiler/typecheck.m
	Don't assume a module qualified cons_id is a function call
	or higher-order pred constant.

compiler/modes.m
compiler/unique_modes.m
compiler/modecheck_unify.m
compiler/instmap.m
compiler/inst_match.m
	Remove some unnecessary conversion between cons_ids and consts.

compiler/typecheck.m
compiler/mode_errors.m
	Strip builtin qualifiers from cons_ids.

compiler/mercury_to_mercury.m
	Output module qualified cons_ids.

compiler/prog_io.m
compiler/prog_io_util.m
	Module qualify constructors in type definitions.
	Parse qualified cons_ids in bound insts.

compiler/hlds_data.m
	Remove cons_id_to_const/3, since it doesn't make much sense any more.
	Add cons_id_arity/2 and cons_id_and_args_to_term/3.

compiler/make_hlds.m
	Add both qualified and unqualified versions of each cons_id to
	the cons_table.

compiler/det_util.m
	Handle module qualified cons_ids in det_util__interpret_unify.

compiler/code_util.m
	Remove some dead code in code_util__cons_id_to_tag to do with
	tags for higher-order terms. Don't assume module qualified
	cons_ids are higher-order pred constants.

compiler/polymorphism.m
	Module qualify type_info cons_ids.
1997-02-17 01:27:10 +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
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
Zoltan Somogyi
3243dbe238 The only significant change in this checkin is that liveness.m now
Estimated hours taken: 0.5

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

The other changes are only syntactic:

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

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

Some of the "read" access predicates in hlds_goal did not have "get" in
their name; I added them.
1996-12-18 11:09:52 +00:00
Fergus Henderson
5f19e2936e Fix a bug that resulted in a map__lookup failed during mode analyis of
Estimated hours taken: 1

Fix a bug that resulted in a map__lookup failed during mode analyis of
procedures that call type-incorrect functions that have no mode declaration.
Unfortunately this fix is not quite complete, since it just defers
the map__lookup failed problem to determinism analysis...
however, this change simplifies the code anyway.

compiler/modes.m:
compiler/hlds_pred.m:
	Simplify the interface to mode_info_never_succeeds so that it
	just takes a proc_info rather than a mode_info plus a pred_id
	plus a proc_id.  Rename it as proc_info_never_succeeds and
	move it from modes.m to hlds_pred.m.

compiler/modecheck_unify.m:
compiler/unique_modes.m:
	Call proc_info_never_succeeds rather than mode_info_never_succeeds.
1996-12-11 18:56:12 +00:00
Zoltan Somogyi
ee24e66a71 Switch from using a stack of store_maps in the code_info to govern what
Estimated hours taken: 2.5

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

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

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

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

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

code_exprn:
	Export a predicate for use by code_info.

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

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

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

follow_vars, store_alloc:
	Add comments.
1996-11-23 10:39:02 +00:00
Andrew Bromage
06e05928e1 Makes instmap and instmap_delta into ADTs.
Estimated hours taken: 38

Makes instmap and instmap_delta into ADTs.

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

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

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

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

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

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

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

	Removed predicates:
		instmapping_lookup_var/3

compiler/mode_util.m:
	Moved merge_instmap_delta/5 to instmap.m
1996-11-19 01:18:24 +00:00
Zoltan Somogyi
5d64b759db The main changes are
Estimated hours taken: 12

The main changes are

1	associating a name with the arguments of constructors

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

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

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

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

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

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

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

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

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

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

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

store_alloc:
	Call follow_vars directly.

follow_vars:
	Expose the initialization and traversal predicates for store_alloc.

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

passes_aux:
	Add a HLDS traversal type for lco.

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

options:
	Set the default value of vnrepeat to 1.

modules:
	Don't refer to .err2 files.
1996-11-04 06:26:51 +00:00
Andrew Bromage
5c149e55b2 Mode analyser reorganisation.
Estimated hours taken: 20

Mode analyser reorganisation.

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

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

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

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

	Moved to mode_errors.m:
		modecheck_report_errors/2

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

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

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

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

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

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

New files:

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

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

compiler/modecheck_call.m:
	Handle mode checking of calls

compiler/mode_debug.m:
        Code to trace the actions of the mode checker.
1996-10-17 05:28:01 +00:00
Simon Taylor
5d3fc10571 - Inter-module optimization.
Estimated hours taken: 50

- Inter-module optimization.
Allows inlining and higher-order specialization across module boundaries.
Gives ~10% speed-up on the compiler compiling to C.

- The code to handle explicit type qualification.
The test to recognise a type qualification is semidet_fail'ed
until we work out which operator to use.

- Improved data structures in module_qual.m.
Also, module qualification of the modes of lambda expressions is now
done in make_hlds.m, since it is more convenient now that type
qualifications are module qualified there also.

* Type qualification and module qualifiers on higher-order predicate
constants and function calls still need to be implemented before this
will work on all programs.

* To create a version of a program using this optimization method,
add --intermodule-optimization to MCFLAGS, mmake change_clean,
mmake depend, then make as normal.

* mmake change_clean removes the executable, the .dep file and all
.cs and .os.

compiler/intermod.m
	Handle input and output of .opt files.

compiler/modules.m
	Added some new dependencies in the .d files for
	the .c and .opt files if inter-module optimization
	is being used.
	Also added .opt and .optdate to the list of things for
	mmake realclean to remove.
	Added a target, change_clean, which removes only those files
	necessary to force a rebuild using --intermodule-optimization.
	These are <module>, <module>.dep and all the .c, .o and .s files.

compiler/options.m
	Added options:
		--make-optimization-interface - make the .opt file.
		--intermodule-optimization - puts extra dependencies
			into .d files and turns on input of .opt files.

compiler/make_hlds.m
	Changes to give items from .opt files the correct import_status.
	Also, when matching pragma_c_code clauses to the declared modes
	of the predicates, expand and match on the initial and final insts
	of the argument modes, not the modes themselves, since items in
	.opt files have the modes expanded.
	Module qualify the modes of lambda expressions in unravel_unification
	rather than during mode analysis.
	Parse explicit type qualifications, and add these to the vartypes.
	At the moment this is disabled.

compiler/typecheck.m
	Get the head type params from the tvarset, not from the arg types,
	so that tvars in type qualifications are included.
	Added checks to prevent matching of predicates, functions and
	constructors which should not be visible to a clause.

compiler/module_qual.m
	Module qualify explicit type qualifications.
	More efficient data structures.

compiler/mercury_to_mercury.m
	Export some predicates. Make sure C code strings are properly
	quoted in the .opt files.

compiler/hlds_out.m
	Output function calls correctly. Alter hlds_out__write_goal to write
	out type qualifications on all functors if writing a .opt file.

compiler/hlds_pred.m
	Added a new import_status opt_imported for clauses and declarations
	read from a .opt file. Pred and func declarations read from a .opt
	file get an `opt_decl' import_status so that the compiler doesn't
	expect clauses for them and local preds can't use them.
	Also added import_status abstract_imported and abstract_exported
	to describe types which have only an abstract definition imported
	or exported.
	Added a field to clauses_info to store the map(var, type) from
	explicit type qualifications.
	Renamed pred_info_set_status/3 to pred_info_set_import_status/3 to
	be consistent with pred_info_import_status/2.

compiler/hlds_data.m
	Added an import_status field to the hlds__mode_defn and
	hlds__inst_defn so that intermod.m knows what has already
	been exported.

compiler/equiv_type.m
	Pass out the equiv_map and export a predicate used to
	expand type qualifications.

compiler/dead_proc_elim.m
	Remove non-optimized versions of opt_imported preds. All
	optimizations must give the optimized version an import_status
	of local.

compiler/code_util.m
	Changed code_util__make_local_entry_label so that `localcall's
	are used for recursive calls in exported predicates.

compiler/code_aux.m
	Changed code_aux__contains_only_builtins_2 so that it doesn't
	check for complicated unifies, since any time this is called,
	complicated unifies have either not been created (when called
	when writing the .opt files) or have been converted to calls
	(when called during inlining).

compiler/higher_order.m
	Make sure that the specialized versions get unique names.

compiler/mercury_compile.pp
	Add calls to intermod.m predicates.

compiler/bytecode_gen.m
	Bracketed some '->'/2 insts so that they can be parsed by SICStus.

compiler/peephole.m
	Replace computed_gotos where all the targets are the same with
	an unconditional goto.

compiler/notes/COMPILER_DESIGN
	Documented intermod.m.

library/list.m
	Added list__all_same/1, which is true if all elements of a list are
	identical. Also added list__last/2, which returns the final element
	of a list, failing on the empty list.

library/io.m
	Change the format specifier for io__write_float so that the decimal
	point is always output. Without this, the result may not be a valid
	Mercury floating point constant.

library/varset.m
	Add predicate varset__create_name_var_map/2 to create a mapping
	from variable name to variable id given a varset. This is used
	in processing type qualifications.

scripts/Mmake.rules
scripts/Mmake.vars.in
	Add suffixes, rules and options for .opt and .optdate.

scripts/mercury_update_interface.in
	Work-around for a problem with parallel gmake. mc --make-interface
	was being run twice in a row on the same module. The first call
	mercury_update_interface moves module.int.tmp to module.int,
	then the second can't find module.int.tmp. The work-around is to
	ignore the exit status of the mv.

Some cleaning up:

compiler/*.m
	Fixed some out of date comments about the handling of
	complicated_unify. Also commented some dead code to do
	with generation of code for complicated_unify.

compiler/modes.m
compiler/mode_info.m
	Moved code to module qualify modes of lambda expressions into
	make_hlds.
	Moved predicates resolve_pred_overloading and find_matching_pred_id
	into typecheck, renaming with a typecheck__ prefix, so that these
	can be called from intermod.m.

compiler/undef_modes.m
compiler/undef_types.m
	Removed - their functionality is now in module_qual.m, except
	for checking for looping equivalence types.

compiler/no_builtin.m
compiler/nit_builtin.m
	Removed - they were made useless (if they weren't already) by
	the removal of the --builtin-module option.

compiler/notes/AUTHORS
	Updated student email addresses.
1996-09-11 08:56:25 +00:00
Fergus Henderson
c8ae82785f Fix bugs which caused the compiler to report spurious unique
Estimated hours taken: 1

Fix bugs which caused the compiler to report spurious unique
mode errors for programs using committed choice nondeterminism,
e.g. samples/committed_choice.m.

det_analysis.m:
	Don't insert `some []' goals for pruning around disjunctions
	that occur in single-solution contexts.  That leads to code
	which creats a choice point and then prunes it.  Instead,
	just make the disjunction itself det, semidet, cc_nondet
	or cc_multidet.  That way, we avoid creating the choice point
	in the first place.

unique_modes.m:
	Make variables non-unique at disjunctions only if the disjunctino
	is a model_non disjunction, rather than doing it for all
	disjunctions.
1996-07-29 16:02:15 +00:00
Simon Taylor
5d9e4158f7 Module qualification of types, insts and modes.
Estimated hours taken: 45

Module qualification of types, insts and modes.

Added a new interface file - <module>.int3. This contains the
short interface qualified as much as possible given the information
in the current module.

When producing the .int and .int2 files for a module, the compiler uses
the information in the .int3 files of modules imported in the interface
to fully module qualify all items. The .int2 file is just a fully
qualified version of the .int3 file. The .int3 file cannot be overwritten
by the fully qualified version in the .int2 file because then mmake would
not be able to tell when the interface files that depend on that .int3
file really need updating.

The --warn-interface-imports option can be used to check whether
a module imported in the interface really needs to be imported in
the interface.


compiler/module_qual.m
Module qualify all types, insts and modes. Also checks for modules
imported in the interface of a module that do not need to be.

compiler/modules.m
The .int file for a module now depends on the .int3 files of imported
modules. Added code to generate the make rule for the .int file in the
.d file. There is now a file .date2 which records the last time the
.int2 file was updated.
The .int3 files are made using the --make-short-interface option
introduced a few weeks ago.

compiler/options.m
Added option --warn-interface-imports to enable warning about interface
imports which need not be in the interface. This is off by default
because a lot of modules in the library import list.m when they only
need the type list, which is defined in mercury_builtin.m.
Removed option --builtin-module, since the mercury_builtin name is wired
into the compiler in a large number of places.

compiler/prog_util.m
Added a predicates construct_qualified_term/3 and construct_qualfied_term/4
which take a sym_name, a list of argument term and a context for the /4
version and give a :/2 term.

compiler/type_util.m
Modified type_to_type_id to handle qualified types. Also added predicates
construct_type/3 and construct_type/4 which take a sym_name and a list of
types and return a type by calling prog_util:construct_qualified_term.

compiler/modes.m
On the first iteration of mode analysis, module qualify the modes of
lambda expressions.

compiler/mode_info.m
Added field to mode_info used to decide whether or not to module qualify
lambda expressions.

compiler/mode_errors.m
Added dummy mode error for when module qualification fails so that mode
analysis will stop.
Added code to strip mercury_builtin qualifiers from error messages to
improve readability.

compiler/typecheck.m
Strip builtin qualifiers from error messages.

compiler/llds.m
compiler/llds_out.m
compiler/opt_util.m
compiler/opt_debug.m
Change the format of labels produced for the predicates to use the
qualified version of the type name.

compiler/mercury_compile.pp
Call module_qual__module_qualify_items and make_short_interface.
Remove references to undef_modes.m and undef_types.m

compiler/undef_modes.m
compiler/undef_types.m
Removed, since their functionality is now in module_qual.m.

compiler/prog_io.m
Changed to qualify the subjects of type, mode and inst declarations.

compiler/*.m
Changes to stop various parts of the compiler from throwing away
module qualifiers.
Qualified various mercury_builtin builtins, e.g. in, out, term etc.
where they are wired in to the compiler.

compiler/hlds_data.m
The mode_table and user_inst_table are now abstract types each
storing the {mode | inst}_id to hlds__{mode | inst}_defn maps
and a list of mode_ids or inst_ids. This was done to improve the
efficiency of module qualifying the modes of lambda expressions
during mode analysis.
module_info_optimize/2 now sorts the lists of ids.
The hlds_module interface to the mode and inst tables has not changed.

compiler/hlds_module.m
Added yet another predicate to search the predicate table.
predicate_table_search_pf_sym_arity searches for predicates or
functions matching the given sym_name, arity and pred_or_func.

compiler/higher_order.m
Changed calls to solutions/2 to list__filter/3. Eliminated unnecessary
requantification of goals.

compiler/unused_args.m
Improved abstraction slightly.
1996-06-11 06:30:10 +00:00
Fergus Henderson
0e1e0b0b91 Implement recursive' and non_recursive' pragma c_code declarations.
Estimated hours taken: 4

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

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

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

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

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

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

*.m:
	Change c_code/5 to c_code/6.
1996-06-10 17:18:50 +00:00
Fergus Henderson
0ac3ffa304 Four loosely related changes to improve mode inference.
Estimated hours taken: 12

Four loosely related changes to improve mode inference.

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

(1) Fix a problem with inference of unique modes.

Previously it was sufficient to just look at the final insts of the
mode and check whether they were `clobbered' or not in order to tell
which arguments will be dead on exit from this procedure.  However,
that doesn't work for inferred modes, where the final inst will
initially be `not_reached'.  Previously mode inference just assumed that
all arguments to a predicate were live, but that prevents it from being
able to infer `di' modes.  So I've added a new field to the proc_info
to record which arguments are required to be dead on exit.
I've also changed mode analysis so that it checks that such
arguments really are dead.  This means you can declare both `di' and
`ui' modes of a predicate, and so long as you declare the `di' one
first, mode checking should handle this overloading.  It also means
that errors such as passing a variable which is live to a procedure with
a `di' mode argument are caught earlier, with a potentially better
error message; mode checking may also be able to reorder such calls,
so that the `di' mode pred is scheduled last.  Mode inference now
notices if an argument is dead, and if so will try infering a `di'
mode.

hlds_pred.m:
	Add a new field to the proc_info, the `maybe_arglives', of type
	`maybe(list(is_live))'.  If set, this records whether or not the
	arguments are required to be dead after the procedure or not.
	Add an access predicate which checks whether this is set,
	and returns either the value set, or if no value special value
	is set, looks up a value based on the modes by calling get_arg_lives
	from mode_util.m.

make_hlds.m:
	Add a MaybeArgLives parameter to add_new_pred.
	(Also change the error messages about pragmas to reflect
	the new pragma syntax.)

clause_to_proc.m, unify_proc.m:
	Pass MaybeArgLives = no to add_new_pred.

modes.m, mode_errors.m:
	Use the new arglives field.  When mode-checking a call (or
	higher-order call), check that all the variables which are
	required to be dead really are dead.

unique_modes.m:
	Use the new arglives field.

mode_util.m:
	Add predicate `get_arg_lives', for use by modes.m and hlds_pred.m.

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

(2) Fix a problem with mode inference looping.

It was checking whether a fixpoint had been reached by comparing the
(un-normalised) inferred final insts with the previously recorded final
insts (which had been normalised).  Instead, it has to normalise the
insts before the comparison.

modes.m:
	When doing mode analysis of an inferred mode, normalise the insts
	before checking whether they've changed, rather than vice versa.

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

(3) Fix a problem with the computation of liveness for mode-analysis
of if-then-elses that was detected when I tried to bootcheck the above
changes.

modes.m, unique_modes.m:
	When mode-checking if-then-elses, the variables in the "else"
	should not be considered live when checking the condition.
	(They're nondet-live, but not live with regard to forward execution.)

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

(4) Reduce the occurrence of mode inference inferring spurious
`in(not_reached)' modes.

modes.m:
	If the top-level inst of a variable becomes `not_reached', set
	the whole instmap to `unreachable'.
1996-05-27 17:15:08 +00:00
Fergus Henderson
81f9959dc3 Fix the handling of error message contexts for mode errors
Estimated hours taken: 4

compiler/{mode_errors.m,mode_info.m,modes.m,unique_modes.m}:
	Fix the handling of error message contexts for mode errors
	so that it does say `in call to predicate foo/2' when it
	means `in call to function foo/1'.
1996-05-26 08:01:09 +00:00
Fergus Henderson
9a7da88ce0 Treat higher-order predicate calls as a new sort of goal,
Estimated hours taken: 24

Treat higher-order predicate calls as a new sort of goal,
rather than as calls to the special predicate call/N, in order to
remove the fixed limit on the number of arguments and on the modes
for call/N.

Also, remove the restriction on output arguments preceding input arguments
in lambda expressions.

hlds_goal.m:
	Add new functor higher_order_call/6 to the hlds__goal type.

*.m:
	Handle new functor higher_order_call/6.

arg_info.m:
	Abstract things a bit more: the argument passing convention
	for a procedure may be affected by that procedure's types,
	modes, and code_model, as well as the arg_method.

follow_vars.m:
	Pass down the args_method, since it is now needed for figuring
	out the arg_info for unifications and higher-order calls.

follow_code.m:
	Treat complicated unifications in the same way as calls.

lambda.m:
	When creating lambda predicates, permute the arguments so
	that all input arguments come before all output arguments.

call_gen.m:
	When generating higher-order predicate calls, don't abort
	if outputs precede inputs; instead, generate code assuming
	that the called predicate's args have been permuted so that
	the inputs to come before all the outputs.
1996-05-02 22:44:50 +00:00
Zoltan Somogyi
e04067b552 A large step in cleaning up the determinism system.
Estimated hours taken: 8

A large step in cleaning up the determinism system.

simplify:
	Determinism analysis should not modify the code of the procedures it
	checks, yet we need to massage some goals to make them acceptable to
	the code generator. The obvious solution is to perform this massaging
	after analysis is finished. This is what this new module does.

det_util:
	New module to hold types and predicates used in more than one module
	involved with the determinism system. Some types and/or predicates
	used to be in switch_detection, det_analysis, det_report, but the
	misc_info type has been expanded and renamed det_info.

det_analysis:
	Don't modify the goal being analyzed except to insert "some" goals.
	This is important because the relevant part of det_analysis knows
	only the current inferred determinism of the goal, not its final
	determinism. The modification code is now in simplify (after some
	fixes).

	Import det_util. Move some utility preds to det_util.
	Export more of the determinism tables; some are needed in simplify.

det_report:
	Import det_util. Move some utility preds to det_util.
	Add some more warning messages.

cse_detection:
	Import det_util.

switch_detection:
	Import det_util. Move some utility preds to det_util.

passes_aux:
	Defined a predicate for traversing the HLDS hierarchy for processing
	all the non-imported procedures.

	Defined write_proc_progress_message to complement
	write_progress_message (which has been renamed
	write_pred_progress_message).

dead_proc_elim, modes, typecheck, unique_modes:
	Use write_{proc/pred}_progress_message as appropriate.

hlds_out:
	Add a new predicate hlds_out__write_pred_proc_id.

hlds_module:
	Improve an abort message.

llds_out:
	Formatting changes.

mercury_compile:
	Call simplify__proc through the new traversal predicate in passes_aux.
1996-04-28 07:25:49 +00:00
Zoltan Somogyi
649b6908c3 Rename branch_delay_slot to have_delay_slot.
Estimated hours taken: 8

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

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

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

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

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

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

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

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

*.m:
	Changes to accommodate the extra field.
1996-04-20 08:37:36 +00:00
Fergus Henderson
16bb3c050a Change the progress messages and error messages to print out
Estimated hours taken: 0.5

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

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

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

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

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

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

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

other modules:
	Import the necessary part of hlds.

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

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

dnf, lambda:
	Simplify the task of defining predicates.

llds:
	Fix some comments.

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

shape, unused_args:
	Fix formatting.
1996-04-02 12:12:24 +00:00
Fergus Henderson
bd2093d8b4 Fixes for two bugs in mode analysis, and
Estimated hours taken: 12

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

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

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

inst_match.m mercury_to_mercury.m mode_util.m modes.m polymorphism.m
prog_io.m switch_detection.m unique_modes.m:
	Fix a design bug: in a `bound' inst, the list of bound_insts
	must be sorted on the name+arity, not on the name+arg_insts.
	To achieve this, I changed the type of the first argument of
	functor/2 in the type bound_inst from `const' (just name) to
	`cons_id' (name+arity).
1996-03-09 16:04:29 +00:00
Fergus Henderson
6d7f4b9b30 Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5

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

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

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

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

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

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

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

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

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

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

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

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

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

This check-in combines several changes.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Rearrange the ordering of the different phases in the compiler.

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

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

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

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

switch_detection.m:
	Recursively traverse lambda goals.

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

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

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

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

lambda.m:
	Make some changes that were needed because lambda.m now comes
	directly after (unique_)modes.m not after polymorphism.m.
1996-01-19 06:02:08 +00:00
Fergus Henderson
ebe792f1d8 A large bunch of changes to improve unique mode checking.
Estimated hours taken: 18

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

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

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

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

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

unique_modes.m:
	Major rewrite.

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

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

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

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

det_analysis.m, det_report.m, make_hlds.m, mercury_compile.pp, prog_io.m,
value_number.m:
	Fix unique mode errors resulting from I/O operations (calls
	to io__lookup_bool_opt) in the conditions of if-then-elses.
1996-01-14 15:16:30 +00:00
Fergus Henderson
49abca54f8 A bit more work on unique mode checking.
Estimated hours taken: 1.5

A bit more work on unique mode checking.

compiler/unique_modes.m:
	Pass around and correctly update the instmap as we traverse the
	goal.
1996-01-13 07:23:45 +00:00
Fergus Henderson
7e0896b906 Propagate nondet-liveness in unifications.
Estimated hours taken: 2

compiler/unique_modes.m:
	Propagate nondet-liveness in unifications.
	Improve the error messages.
1996-01-05 07:06:16 +00:00
Fergus Henderson
71df996a9f Add code to compute a very dumb but conservative approximation
Estimated hours taken: 0.75

unique_modes.m:
	Add code to compute a very dumb but conservative approximation
	to the set of nondet-live variables.
	Check final insts as well as initial insts.
1996-01-01 14:22:55 +00:00
Fergus Henderson
e2d7877b0f Improve error message for one of the internal errors.
code_exprn.m:
	Improve error message for one of the internal errors.

det_analysis.m:
	Make sure we don't generated unnecessary nested `some' goals.

prog_io.m, inst_match.m, mode_util.m, mercury_to_mercury.m:
	Add new insts `mostly_unique' and `mostly_clobbered', with
	semantics similar to `unique' and `clobbered', except that
	mostly-unique variables might be needed on backtracking.

unique_modes.m:
	A good start on the code to check that `unique' modes
	are not used for nondet live variables.  Still incomplete,
	but just about all the code is there except the code to
	actually compute the set of nondet live variables as you
	traverse the goal.
1996-01-01 13:19:22 +00:00