Commit Graph

209 Commits

Author SHA1 Message Date
Zoltan Somogyi
672f77c4ec Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20
Branches: main

Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled,
the compiler will generate informational messages about if-then-elses that
it thinks should be converted to switches for the sake of program reliability.

Act on the output generated by this option.

compiler/simplify.m:
	Implement the new option.

	Fix an old bug that could cause us to generate warnings about code
	that was OK in one duplicated copy but not in another (where a switch
	arm's code is duplicated due to the case being selected for more than
	one cons_id).

compiler/options.m:
	Add the new option.

	Add a way to test for the bug fix in simplify.

doc/user_guide.texi:
	Document the new option.

NEWS:
	Mention the new option.

library/*.m:
mdbcomp/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
	Convert if-then-elses to switches at most of the sites suggested by the
	new option. At the remaining sites, switching to switches would have
	nontrivial downsides. This typically happens with the switched-on type
	has many functors, and we treat one or two specially (e.g. cons/2 in
	the cons_id type).

	Perform misc cleanups in the vicinity of the if-then-else to switch
	conversions.

	In a few cases, improve the error messages generated.

compiler/accumulator.m:
compiler/hlds_goal.m:
	(Rename and) move insts for particular kinds of goal from
	accumulator.m to hlds_goal.m, to allow them to be used in other
	modules. Using these insts allowed us to eliminate some if-then-elses
	entirely.

compiler/exprn_aux.m:
	Instead of fixing some if-then-elses, delete the predicates containing
	them, since they aren't used, and (as pointed out by the new option)
	would need considerable other fixing if they were ever needed again.

compiler/lp_rational.m:
	Add prefixes to the names of the function symbols on some types,
	since without those prefixes, it was hard to figure out what type
	the switch corresponding to an old if-then-else was switching on.

tests/invalid/reserve_tag.err_exp:
	Expect a new, improved error message.
2007-11-23 07:36:01 +00:00
Zoltan Somogyi
168f531867 Add new fields to the goal_info structure for region based memory management.
Estimated hours taken: 4
Branches: main

Add new fields to the goal_info structure for region based memory management.
The fields are currently unused, but (a) Quan will add the code to fill them
in, and then (b) I will modify the code generator to use the filled in fields.

compiler/hlds_goal.m:
	Make the change described above.

	Group all the procedures that access goal_info components together.
	Some of the getters were predicates while some were functions, so
	this diff changes them all to be functions. (The setters remain
	predicates.)

compiler/*.m:
	Trivial changes to conform to the change in hlds_goal.m.

	In simplify.m, break up a huge (800+ line) predicate into smaller
	pieces.
2007-08-07 07:10:09 +00:00
Julien Fischer
9482049101 Fix an inconsistency between the compiler's handling of foreign_import_module
Estimated hours taken: 4
Branches: main

Fix an inconsistency between the compiler's handling of foreign_import_module
pragmas (which was itself inconsistent between backends) and what is documented
about that pragma in the reference manual.

According to the reference manual if foreign code (in either a foreign_proc or
foreign_code pragma) wants to refer to pragma foreign_exported procedures from
the same module then there needs to be a foreign_import_module in the module
for itself.

The high-level C backend ignores this entirely and modules always effectively
implicitly foreign import themselves.  The situation with the low-level C
backend varies depending on whether a module has any children or not; if it
does then it does not implicitly foreign import itself otherwise it does.

This diff changes the language to require that modules always implicitly
foreign import themselves and adds a workaround to the low-level C backend
to make sure this always happens.  (A better fix would be to modify
the frontend of the compiler to handle the implicit foreign imports
for both backends but the lack of structure in the parse tree makes this
quite awkward at the moment.)

Fix a bunch of comments that were out-of-date.

doc/reference_manual.texi:
	Change the description of behaviour of
	`:- pragma foreign_import_module' so that it matches what the
	implementation actually does (well, at least what it actually
	does most of the time.)  The new behaviour removes the requirement
	that modules need to foreign_import themselves.  This is pretty much
	what users (and implementors) have assumed anyway

compiler/mercury_compile.m:
	Make sure that in LLDS grades modules always foreign import themselves
	(this was the exception to "most of the time" above.)

	Change an if-then-else into a switch.

tests/hard_coded/sub-modules/Makefile:
tests/hard_coded/sub-modules/sm_exp_bug.m:
tests/hard_coded/sub-modules/sm_exp_bug.child.m:
tests/hard_coded/sub-modules/sm_exp_bug.exp:
	Test case for the above.

compiler/mlds.m:
	Update a comment.  pragma foreign_export has been implemented
	for other backends.

compiler/modules.m:
	Fix the formatting of the module_imports structure.

	Divide some of this module more visibly into sections.

compiler/process_util.m:
	Replace a pragma_export with pragma foreign_export.

compiler/add_pragma.m:
compiler/det_analysis.m:
compiler/export.m:
compiler/hlds_module.m:
compiler/make.m:
compiler/make_hlds_passes.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
compiler/prog_foreign.m:
	s/pragma export/pragma foreign_export/

compiler/make_hlds.m:
compiler/prog_io_pragma.m:
compiler/prog_item.m:
	Minor formatting fixes.
2007-03-04 23:38:09 +00:00
Ralph Becket
2169f6f52f Fix a bug where promise_equivalent_solutions complained both if you did or did
Estimated hours taken: 1
Branches: main

Fix a bug where promise_equivalent_solutions complained both if you did or did
not include non-locals with inst any in the var list.  Such vars *must* now be
included in the list.

NEWS:
	Mention the change.

compiler/det_analysis.m:
	Require inst any non-locals to appear in the var list.

compiler/instmap.m:
	Added var_is_any_in_instmap.

doc/reference_manual.texi:
	Document the change.

tests/invalid/Mmakefile:
tests/invalid/promise_equivalent_solutions_test_2.err_exp:
tests/invalid/promise_equivalent_solutions_test_2.m:
	Added a test case.
2007-02-05 03:12:54 +00:00
Zoltan Somogyi
b56885be93 Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail.
Estimated hours taken: 12
Branches: main

Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail.

The problem was not in lco.m, but in follow_code.m. In some cases,
(specifically, the LCMC version of insert_2 in sparse_bitset.m),
follow_code.m moved an impure goal (store_at_ref) into the arms of an
if-then-else without marking those arms, or the if-then-else, as impure.
The next pass, simplify, then deleted the entire if-then-else, since it
had no outputs. (The store_at_ref that originally appeared after the
if-then-else was the only consumer of its only output.)

The fix is to get follow_code.m to make branched control structures such as
if-then-elses, as well as their arms, semipure or impure if a goal being moved
into them is semipure or impure, or if they came from an semipure or impure
conjunction.

Improve the optimization of the LCMC version of sparse_bitset.insert_2, which
had a foreign_proc invocation of bits_per_int in it: replace such invocations
with a unification of the bits_per_int constant if not cross compiling.

Add a new option, --optimize-constructor-last-call-null. When set, LCMC will
assign NULLs to the fields not yet filled in, to avoid any junk happens to be
there from being followed by the garbage collector's mark phase.

This diff also makes several other changes that helped me to track down
the bug above.

compiler/follow_code.m:
	Make the fix described above.

	Delete all the provisions for --prev-code; it won't be implemented.

	Don't export a predicate that is not now used anywhere else.

compiler/simplify.m:
	Make the optimization described above.

compiler/lco.m:
	Make sure that the LCMC specialized procedure is a predicate, not a
	function: having a function with the mode LCMC_insert_2(in, in) = in
	looks wrong.

	To avoid name collisions when a function and a predicate with the same
	name and arity have LCMC applied to them, include the predicate vs
	function status of the original procedure included in the name of the
	new procedure.

	Update the sym_name of calls to LCMC variants, not just the pred_id,
	because without that, the HLDS dump looks misleading.

compiler/pred_table.m:
	Don't have optimizations like LCMC insert new predicates at the front
	of the list of predicates. Maintain the list of predicates in the
	module as a two part list, to allow efficient addition of new pred_ids
	at the (logical) end without using O(N^2) algorithms. Having predicates
	in chronological order makes it easier to look at HLDS dumps and
	.c files.

compiler/hlds_module.m:
	Make module_info_predids return a module_info that is physically
	updated though logically unchanged.

compiler/options.m:
	Add --optimize-constructor-last-call-null.

	Make the options --dump-hlds-pred-id, --debug-opt-pred-id and
	--debug-opt-pred-name into accumulating options, to allow the user
	to specify more than one predicate to be dumped (e.g. insert_2 and
	its LCMC variant).

	Delete --prev-code.

doc/user_guide.texi:
	Document the changes in options.m.

compiler/code_info.m:
	Record the value of --optimize-constructor-last-call-null in the
	code_info, to avoid lookup at every cell construction.

compiler/unify_gen.m:
compiler/var_locn.m:
	When deciding whether a cell can be static or not, make sure that
	we never make static a cell that has some fields initialized with
	dummy zeros, to be filled in for real later.

compiler/hlds_out.m:
	For goals that are semipure or impure, note this fact. This info was
	lost when I changed the representation of impurity from markers to a
	field.

mdbcomp/prim_data.m:
	Rename some ambiguous function symbols.

compiler/intermod.m:
compiler/trans_opt.m:
	Rename the main predicates (and some function symbols) of these modules
	to avoid ambiguity and to make them more expressive.

compiler/llds.m:
	Don't print line numbers for foreign_code fragments if the user has
	specified --no-line-numbers.

compiler/make.dependencies.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.usage.m:
	Don't use io.write to write out information to files we may need to
	parse again, because this is vulnerable to changes to the names of
	function symbols (e.g. the one to mdbcomp/prim_data.m).

	The compiler still contains some uses of io.write, but they are
	for debugging. I added an item to the todo list of the one exception,
	ilasm.m.

compiler/recompilation.m:
	Rename a misleading function symbol name.

compiler/parse_tree.m:
	Don't import recompilation.m here. It is not needed (all the components
	of parse_tree that need recompilation.m already import it themselves),
	and deleting the import avoids recompiling almost everything when
	recompilation.m changes.

compiler/*.m:
	Conform to the changes above.

compiler/*.m:
browser/*.m:
slice/*.m:
	Conform to the change to mdbcomp.

library/sparse_bitset.m:
	Use some better variable names.
2007-01-19 07:05:06 +00:00
Zoltan Somogyi
ba93a52fe7 This diff changes a few types from being defined as equivalent to a pair
Estimated hours taken: 10
Branches: main

This diff changes a few types from being defined as equivalent to a pair
to being discriminated union types with their own function symbol. This
was motivated by an error message (one of many, but the one that broke
the camel's back) about "-" being used in an ambiguous manner. It will
reduce the number of such messages in the future, and will make compiler
data structures easier to inspect in the debugger.

The most important type changed by far is hlds_goal, whose function symbol
is now "hlds_goal". Second and third in importance are llds.instruction
(function symbol "llds_instr") and prog_item.m's item_and_context (function
symbol "item_and_context"). There are some others as well.

In several places, I rearranged predicates to factor the deconstruction of
goals into hlds_goal_expr and hlds_goal_into out of each clause into a single
point. In many places, I changed variable names that used "Goal" to refer
to just hlds_goal_exprs to use "GoalExpr" instead. I also changed variable
names that used "Item" to refer to item_and_contexts to use "ItemAndContext"
instead. This should make reading such code less confusing.

I renamed some function symbols and predicates to avoid ambiguities.

I only made one algorithmic change (at least intentionally).
In assertion.m, comparing two goals for equality now ignores goal_infos
for all kinds of goals, whereas previously it ignored them for most kinds
of goals, but for shorthand goals it was insisting on them being equal.
This seemed to me to be a bug. Pete, can you confirm this?
2007-01-06 09:23:59 +00:00
Zoltan Somogyi
07b216c4fb Treat trace goals as quantifying the variables that occur in their io() and/or
Estimated hours taken: 2
Branches: main

Treat trace goals as quantifying the variables that occur in their io() and/or
state() components.

compiler/hlds_goal.m:
	Extend trace scopes with a field for recording the set of quantified
	variables.

compiler/add_clause.m:
	Record the list of quantified variables.

compiler/quantification.m:
	Treat the list of quantified variables as for other scopes.

compiler/hlds_out.m:
	Write out the new field.

compiler/mercury_to_mercury.m:
	Reorder the arguments of some predicates to make them easier to curry,
	e.g. for the new code in hlds_out.m.

	Rename some predicates to avoid ambiguities.

compiler/*.m:
	Conform to the changes in hlds_goal.m and/or mercury_to_mercury.m.

tests/hard_coded/trace_goal_3.{m,exp}:
	New test case to test the new functionality.

tests/hard_coded/Mmakefile:
	Enable the new test case.
2006-11-06 07:55:14 +00:00
Zoltan Somogyi
e21193c283 Rename a bunch of predicates and function symbols to eliminate
Estimated hours taken: 6
Branches: main

browser/*.m:
compiler/*.m:
	Rename a bunch of predicates and function symbols to eliminate
	ambiguities.

	The only real change is factoring out some common code in the mlds
	and llds code generators, replacing them with single definitions
	in switch_util.m.
2006-10-15 23:26:56 +00:00
Zoltan Somogyi
411b45846a Modify check_typeclass.m to gather up all error messages, and print them all
Estimated hours taken: 12
Branches: main

Modify check_typeclass.m to gather up all error messages, and print them all
at once after sorting.

Modify the determinism analysis pass to generate error_specs directly, instead
of generating context_det_msgs and converting those to error_specs later.

Separate the simplify pass's mechanism for generating error messages from
the determinism pass.

compiler/check_typeclass.m:
	Return all error messages instead of printing them when generated.

	Keep the error messages outside the instance_method_info structure,
	and give the fields of the structure names.

compiler/det_analysis.m:
	Generate error specs directly.

compiler/det_report.m:
	Delete the context_det_msg data type and the predicates that operated
	on it, since they are no longer needed. The code that used to convert a
	context_det_msg into an error_spec is now dispersed to the sites that
	generate the error report in the first place. These sites are mostly
	in det_analysis.m and simplify.m, with a few in other modules
	(e.g. common.m and format_call.m). Export some auxiliary functions
	that the these sites now need.

compiler/simplify.m:
	Generate error_specs directly, instead of through context_det_msgs,
	and return them to the caller for printing.

compiler/common.m:
compiler/format_call.m:
	Conform to the change to det_report.m.

compiler/unused_import.m:
	Return all error messages instead of printing them when generated.

compiler/mercury_compile.m:
	Print the error message batches returned by the modified passes.

	Use the version of globals in module_infos in preference to the one
	in the I/O state, since we would like to phase out the latter.

	Don't explicitly sort error_specs, since write_error_specs will do
	it anyway.

compiler/error_util.m:
	Separate the error messages of the simplify pass from those of
	determinism analysis.

	Provide a standard way to format type constructor names.

	Require the calls to provide the globals when printing error_specs.
	This is to allow callers to provide the globals from a module_info,
	instead of the one in the I/O state.

compiler/passes_aux.m:
	Provide support for passes that have lists of error_specs threaded
	through them, as simplify now does.

	Rename some predicates to avoid some ambiguities.

compiler/deforest.m:
compiler/pd_util.m:
compiler/unify_proc.m:
compiler/unused_args.m:
	Conform to the change to the interface of determinism analysis.

compiler/inlining.m:
	Do not thread the I/O state through this module.

compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/ml_tailcall.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/modules.m:
compiler/stratify.m:
compiler/table_gen.m:
	Conform to the change in error_util.

compiler/prog_data.m:
	Rename some function symbols to avoid some ambiguities.

compiler/add_class.m:
compiler/base_typeclass_info.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/module_qual.m:
compiler/prog_io_typeclass.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/type_class_info.m:
	Conform to the change in prog_data.m.

tests/invalid/*err_exp:
	Update the expected output files to conform to the changes above.
	This mosly involves expecting sorted messages without duplicates.
2006-10-13 04:52:38 +00:00
Peter Ross
84ffc0924d Fix --warn-unused-imports warnings in some of the modules.
Estimated hours taken: 4
Branches: main

library/*.m:
compiler/*.m:
	Fix --warn-unused-imports warnings in some of the modules.
2006-09-27 06:17:09 +00:00
Zoltan Somogyi
00741b0162 This diff contains no algorithmic changes.
Estimated hours taken: 6
Branches: main

This diff contains no algorithmic changes. It merely renames apart a bunch more
function symbols to reduce ambiguity.

After this diff, the summary line from the mdb command "ambiguity -f" is

	Total: 351 names used 975 times, maximum 31, average: 2.78

browser/*.m:
compiler/*.m:
	Rename function symbols to eliminate ambiguities.

tests/debugger/declarative/dependency.exp:
tests/debugger/declarative/dependency2.exp:
	Update the expected out where some internal function symbol names
	appear in the output of the debugger. (This output is meant for
	implementors only.)
2006-08-22 05:04:29 +00:00
Zoltan Somogyi
2b2f3d3cbe This diff contains no algorithmic changes.
Estimated hours taken: 8
Branches: main

This diff contains no algorithmic changes. It merely renames apart a bunch of
function symbols to reduce ambiguity. Basically I went through prog_data.m,
prog_item.m, hlds_data.m, hlds_goal.m and hlds_pred.m looking for type
definitions containing function symbol names that were either language
"keywords" (e.g. "terminates", which is an annotation on foreign_procs),
used with slightly different meanings in several types (e.g. "sym"),
or both (e.g. "call"). When I found such type definitions, I changed the
names of the function symbols, usually by adding a prefix or suffix
indicating the type to all function symbols of the type. For example,
the old function symbol "foreign_proc" in type "pragma_type" is now named
"pragma_foreign_proc", and the names of all other function symbols in that
type also start with "pragma_".

All of this should yield simpler compiler error messages when we make mistakes,
and will make it more likely that looking up a function symbol using a tags
file will take you to the actual definition of the relevant instance of that
function symbol. However, the most important benefit is the increase in
the readability of unfamiliar code; the reader won't have to emulate the
compiler's type ambiguity resolution algorithm (which in many cases used to
require distinguishing between f/14 and f/15 by counting the arguments,
e.g. for "pred_or_func").

compiler/prog_data.m:
compiler/prog_item.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Rename function symbols as explained above.

compiler/*.m:
	Conform to the function symbol renames.

	In some cases, rename other function symbols as well.

	Minor style fixes, e.g. replace if-then-elses with switches,
	or simple det predicates with functions.
2006-08-20 08:21:36 +00:00
Julien Fischer
aeeedd2c13 Standardize formatting of comments at the beginning of modules.
compiler/*.m:
	Standardize formatting of comments at the beginning of modules.
2006-07-31 08:32:11 +00:00
Zoltan Somogyi
9d23d8e2e7 Implement the trace goal construct we discussed, for now for the LLDS backends
Estimated hours taken: 70
Branches: main

Implement the trace goal construct we discussed, for now for the LLDS backends
only.

Since the syntax of trace goals is non-trivial, useful feedback on syntax
errors inside trace goal attributes is essential. With the previous setup, this
wasn't possible, since the code that turned terms into parse tree goals turned
*all* terms into goals; it couldn't recognize any errors, sweeping them under
the rug as calls. This diff changes that. Now, if this code recognizes a
keyword that indicates a particular construct, it insists on the rest of the
code following the syntax required for that construct, and returns error
messages if it doesn't.

We handle the trace goal attributes that specify state variables to be threaded
through the trace goal (either the I/O state or a mutable variable) in
add_clause.m, at the point at which we transform the list of items to the HLDS.
We handle the compile-time condition on trace goals in the invocation of
simplify at the end of semantics analysis, by eliminating the goal if the
compile-time condition isn't met. We handle run-time conditions on trace goals
partially in the same invocation of simplify: we transform trace goals with
runtime conditions into an if-then-else with the trace goal as the then part
and `true' as the else part, the condition being a foreign_proc that is handled
specially by the code generator, that special handling being to replace
the actual code of the foreign_proc (which is a dummy) with the evaluation of
the runtime condition.

Since these changes require significant changes to some of our key data
structures, I took the liberty of doing some renaming of function symbols
at the same time to avoid using ambiguities with respect to language keywords.

library/ops.m:
	Add "trace" as an operator.

compiler/prog_data.m:
	Define data types to represent the various attributes of trace goals.

	Rename some function symbols to avoid ambiguities.

compiler/prog_item.m:
	Extend the parse tree representation of goals with a trace goal.

compiler/mercury_to_mercury.m:
	Output the new kind of goal and its components.

compiler/hlds_goal.m:
	Extend the HLDS representation of scopes with a scope_reason
	representing trace goals.

	Add a mechanism (an extra argument in foreign_procs) to allow
	the representation of goals that evaluate runtime trace conditions.

	Since this requires modifying all code that traverses the HLDS,
	do some renames that were long overdue: rename not as negation,
	rename call as plain_call, and rename foreign_proc as
	call_foreign_proc. These renames all avoid using language keywords
	as function symbols.

	Change the way we record goals' purities. Instead of optional features
	to indicate impure or semipure, which is error-prone, use a plain
	field in the goal_info, accessed in the usual way.

	Add a way to represent that a goal contains a trace goal, and should
	therefore be treated as if it were impure when considering whether to
	optimize it away.

	Reformat some comments describing function symbols.

compiler/hlds_out.m:
	Output the new construct in the HLDS.

compiler/prog_io_util.m:
	Generalize the maybe[123] types to allow the representation of more
	than one error message. Add functions to extract the error messages.
	Add a maybe4 type. Rename the function symbols of these types to
	avoid massive ambiguity.

	Change the order of some predicates to bring related predicates
	next to each other.

compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
	Rework these modules almost completely to find and accumulate syntax
	errors as terms are being parsed. In some cases, this allowed us to
	replace "XXX this is a hack" markers with meaningful error-reporting
	code.

	In prog_io_goal.m, add code for parsing trace goals.

	In a bunch of places, update obsolete coding practices, such as using
	nested chains of closures instead of simple sequential code, and
	using A0 and A to refer to values of different types (terms and goals
	respectively). Use more meaningful variable names.

	Break up some too-large predicates.

compiler/superhomogeneous.m:
	Find and accumulate syntax errors as terms are being parsed.

compiler/add_clause.m:
	Add code to transform trace goals from the parse tree to the HLDS.
	This is where the IO state and mutable variable attributes of trace
	goals are handled.

	Eliminate the practice of using the naming scheme Body0 and Body
	to refer to values of different types (prog_item.goal and hlds_goal
	respectively).

	Use error_util for some error messages.

library/private_builtin.m:
	Add the predicates referred to by the transformation in add_clause.m.

compiler/goal_util.m:
	Rename a predicate to avoid ambiguity.

compiler/typecheck.m:
	Do not print error messages about missing clauses if some errors have
	been detected previously.

compiler/purity.m:
	Instead of just computing purity, compute (and record) also whether
	a goal contains a trace goal. However, treat trace goals as pure.

compiler/mode_info.m:
	Add trace goals as a reason for locking variables.

	Rename some function symbols to avoid ambiguity.

compiler/modes.m:
	When analyzing trace goal scopes, lock the scope's nonlocal variables
	to prevent them from being further instantiated.

compiler/det_analysis.m:
	Insist on the code in trace goal scopes being det or cc_multi.

compiler/det_report.m:
	Generate the error message if the code in a trace goal scope isn't det
	or cc_multi.

compiler/simplify.m:
	At the end of the front end, eliminate trace goal scopes if their
	compile-time condition is false. Transform trace goals with runtime
	conditions as described at the top.

	Treat goals that contain trace goals as if they were impure when
	considering whether to optimize them away.

compiler/mercury_compile.m:
	Tell simplify when it is being invoked at the end of the front end.

	Rename a predicate to avoid ambiguity.

compiler/trace_params.m:
	Provide the predicates simplify.m need to be able to evaluate the trace
	goal conditions regarding trace levels.

compiler/trace.m:
compiler/trace_gen.m:
	Rename the trace module as trace_gen, since "trace" is now an operator.

	Rename some predicates exported by the module, now that it is no longer
	possible to preface calls with "trace." as a module qualifier.

compiler/notes/compiler_design.html:
	Document this name change.

compiler/options.m:
	Rename the trace option as trace_level internally, since "trace"
	is now an operator. The user-visible name remains the same.

	Add the new --trace-flag option.

	Delete an obsolete option.

compiler/handle_options.m:
	Rename the function symbols of the grade_component type,
	since "trace" is now an operator.

compiler/llds.m:
	Extend the LLDS with a mechanism to refer to C global variables.
	For now, these are used to refer to C globals that will be created
	by mkinit to represent the initial values of the environment variables
	referred to by trace goals.

compiler/commit_gen.m:
	Check that no trace goal with a runtime condition survives to code
	generation; they should have been transformed by simplify.m.

compiler/code_gen.m:
	Tell commit_gen.m what kind of scope it is generating code for.

compiler/pragma_c_gen.m:
	Generate code for runtime conditions when handling the foreign_procs
	created by simplify.m.

compiler/code_info.m:
	Allow pragma_c_gen.m to record what environment variables it has
	generated references to.

compiler/proc_gen.m:
	Record the set of environment variables a procedure refers to
	in the LLDS procedure header, for efficient access by llds_out.m.

compiler/llds_out.m:
	Handle the new LLDS construct, and tell mkinit which environment
	variables need C globals created for them.

compiler/pd_util.m:
	Rename some predicates to avoid ambiguity.

compiler/*.m:
	Conform to the changes above, mainly the renames of function symbols
	and predicates, the changed signatures of some predicates, and the new
	handling of purity.

util/mkinit.c:
	Generate the definitions and the initializations of any C globals
	representing the initial status (set or not set) of environment
	variables needed by trace goals.

library/assoc_list.m:
	Add some predicates that are useful in prog_io*.m.

library/term_io.m:
	Minor cleanup.

tests/hard_coded/trace_goal_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at compile time.

tests/hard_coded/trace_goal_env_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at run time.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
	Enable the new test cases.

tests/invalid/*.err_exp:
	Update the expected output for the new versions of the error messages
	now being generated.
2006-07-27 05:03:54 +00:00
Julien Fischer
81907122a3 Implement `:- pragma foreign_export'. This is intended to be a replacement
Estimated hours taken: 12
Branches: main

Implement `:- pragma foreign_export'.  This is intended to be a replacement
for `:- pragma export'.  The principle difference is that `:- pragma
foreign_export' allows you to restrict exports to a particular foreign
language.  This language will usually be the target language but in the case
of backends that support multiple foreign languages, e.g. the IL backend, it
also allows us to restrict the exports to a subset of the available foreign
languages.

Add some support for exporting procedures in the Java backend.  This is
currently undocumented because I cannot test it properly while the Java
backend is not working.  (The reason for adding the support was to make sure
that all of the MLDS backends were handling foreign_export declarations
correctly.)

Make the compiler emit warnings about exports for Java, IL, C# and MC++ not
yet being implemented.  For the latter two this is true.  As mentioned above
this change adds some support for exports in the Java backend and there was
some pre-existing (but undocumented) support for exports to IL.  (The warnings
can be deleted once exports for these languages are properly documented and/or
implemented.)

compiler/prog_item.m:
	Rename the export item to foreign_export for consistency with the
	rest of the items concerned with the foreign language interface.

	Add an extra field to that item.  The new field stores the foreign
	language that the pragma applies to.

compiler/prog_io_pragma.m:
	Parse foreign_export pragmas.

	Implement `:- pragma export' declarations as a special case of
	`:- pragma foreign_export' declarations.

compiler/add_pramga.m:
	Rename some predicates.

	Emit warnings about foreign_exports to languages that we do not
	currently support.

compiler/export.m:
	Rename some of the predicates in this module to make them more C
	specific.

	Handle foreign exports for the lowlevel C backend.

compiler/hlds_module.m:
	Add an extra field to the pragma_exported_proc structure to hold the
	name of the foreign language that the corresponding foreign_export
	declaration is for.

compiler/mercury_to_mercury.m:
	Add code to output foreign_export pragmas.

compiler/ml_code_gen.m:
	Don't filter out exports for Java, C# and MC++.  The Java exports
	can now be passed down to mlds_to_java.m and the other two ought to
	be caught by the frontend of the compiler.

compiler/mlds_to_java.m
	Add a tentative implementation of pragma foreign_export for Java.
	This is currently not documented in the reference manual because
	it is (largely) untested.

compiler/mlds_to_c.m:
	Change an if-then-else to a switch.

	Add a sanity check.  Exports for languages other than C should not
	reach here.

compiler/mlds_to_il.m:
	Update the TODO list at the head of this file.

	Add a sanity check.  Exports for languages other than IL should not
	reach here.

compiler/dead_proc_elim.m:
compiler/det_analysis.m:
compiler/foreign.m:
compiler/handle_options.m:
compiler/make_hlds_passes.m:
compiler/mlds.m:
compiler/mlds_to_managed.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
	Conform to the above changes.

	Minor formatting changes.

doc/reference_manual.texi:
	Add a new section to the foreign language interface chapter
	documenting the new pragma.

	Update the descriptions of the language specific bindings to include
	the new pragma.

tests/hard_coded/Mmakefile:
tests/hard_coded/pragma_foreign_export.{m,exp}:
	Make sure that we can parse the new syntax and run a simple program
	that uses exported procedures.

tests/invalid/invalid_export_detism.{m,err_exp}:
	Update this test case to conform to the new pragma name.
2006-07-19 15:19:09 +00:00
Zoltan Somogyi
fb9f78b784 Fix a bug reported by Peter Hawkins. The bug was that an predicate without
Estimated hours taken: 3
Branches: main

Fix a bug reported by Peter Hawkins. The bug was that an predicate without
a declared determinism but whose inferred determinism was invalid for its
tabling declaration led to a compiler abort.

compiler/det_analysis.m:
	Fix the main cause of the bug, which was that the check for the
	compatibility of evaluation method and determinism was performed
	only for predicates with declared determinisms, not those without.

	Centralize the printing of determinism error messages, and sort
	the messages first.

compiler/hlds_pred.m:
	Fix the other half of the bug: the predicate that checked the
	compatibility of evaluation method and determinism was too liberal
	with minimal model predicates, letting through determinisms that the
	tabling transformation cannot (yet) support.

compiler/det_report.m:
	Fix the formatting of the error message.

compiler/prog_data.m:
	Rename the function symbols of the type "determinism", to avoid
	conflicts with language keywords.

compiler/*.m:
	Conform to the change to prog_data.m.

tests/invalid/hawkins_mm_fail_reset.{m,err_exp}:
	New test case for the bug being fixed.

tests/invalid/Mmakefile:
	Enable the new test case.

tests/invalid/loopcheck.err_exp:
	Expect the new format of the improved error message.
2006-07-12 02:51:22 +00:00
Julien Fischer
459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00
Zoltan Somogyi
12deb40264 Rename all the get access predicates in these modules that don't
Estimated hours taken: 0.1
Branches: main

compiler/hlds_clauses.m:
compiler/hlds_pred.m:
	Rename all the get access predicates in these modules that don't
	already have put "get" in their name. (The names of the set access
	predicates were OK already.)

compiler/*.m:
	Conform to the above.

All this was done by this sed script:

s/clauses_info_varset/clauses_info_get_varset/
s/clauses_info_explicit_vartypes/clauses_info_get_explicit_vartypes/
s/clauses_info_vartypes/clauses_info_get_vartypes/
s/clauses_info_headvars/clauses_info_get_headvars/
s/clauses_info_clauses_rep/clauses_info_get_clauses_rep/
s/clauses_info_rtti_varmaps/clauses_info_get_rtti_varmaps/
s/pred_info_import_status/pred_info_get_import_status/
s/pred_info_arg_types/pred_info_get_arg_types/
s/pred_info_typevarset/pred_info_get_typevarset/
s/pred_info_tvar_kinds/pred_info_get_tvar_kinds/
s/pred_info_procedures/pred_info_get_procedures/
s/proc_info_context/proc_info_get_context/
s/proc_info_varset/proc_info_get_varset/
s/proc_info_vartypes/proc_info_get_vartypes/
s/proc_info_headvars/proc_info_get_headvars/
s/proc_info_inst_varset/proc_info_get_inst_varset/
s/proc_info_maybe_declared_argmodes/proc_info_get_maybe_declared_argmodes/
s/proc_info_argmodes/proc_info_get_argmodes/
s/proc_info_maybe_arglives/proc_info_get_maybe_arglives/
s/proc_info_declared_determinism/proc_info_get_declared_determinism/
s/proc_info_inferred_determinism/proc_info_get_inferred_determinism/
s/proc_info_goal/proc_info_get_goal/
s/proc_info_can_process/proc_info_get_can_process/
s/proc_info_rtti_varmaps/proc_info_get_rtti_varmaps/
s/proc_info_eval_method/proc_info_get_eval_method/
s/proc_info_is_address_taken/proc_info_get_is_address_taken/
s/proc_info_stack_slots/proc_info_get_stack_slots/
s/proc_info_liveness_info/proc_info_get_liveness_info/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
2006-03-27 09:36:34 +00:00
Zoltan Somogyi
3ebda6545f Move the stuff currently in hlds_pred.m that deals with clauses into a new
Estimated hours taken: 1.5
Branches: main

Move the stuff currently in hlds_pred.m that deals with clauses into a new
module, hlds_clauses.m.

Move the stuff currently in hlds_pred.m that deals with RTTI into a new
module, hlds_rtti.m.

Move the stuff currently in hlds_module.m that deals with predicate tables
into a new module, pred_table.m.

These changes make hlds_pred.m and hlds_module.m much more cohesive, but there
are no changes in algorithms.

compiler/hlds_clauses.m:
compiler/hlds_rtti.m:
compiler/pred_table.m:
	New modules as described above. In some cases, fix mixleading or
	ambiguous predicate names in the process, and convert a few predicates
	to functions.

compiler/hlds_pred.m:
compiler/hlds_module.m:
	Delete the stuff moved to other modules.

compiler/*.m:
	In modules that need the functionality moved a new module, import
	the new module. It is rare for all the new modules to be needed,
	and many modules don't need any of the new modules at all. (For
	example, of the 200+ modules that import hlds_module.m, only about 40
	need pred_table.m.)

	Conform to the few minor changes to e.g. predicate names.

compiler/notes/compiler_design.html:
	Document the new modules.
2006-03-24 03:04:20 +00:00
Zoltan Somogyi
836fcf964e Replace __ with .
Estimated hours taken: 0.1
Branches: main

compiler/det_analysis.m:
	Replace __ with .
2006-03-22 00:45:59 +00:00
Zoltan Somogyi
19159de6b7 Add a new goal form, as discussed on our mailing lists:
Estimated hours taken: 12
Branches: main

Add a new goal form, as discussed on our mailing lists:

	promise_equivalent_solution_sets [Vars] (
		arbitrary [Vars1] Goal1,
		arbitrary [Vars2] Goal2,
		...
	)

NEWS:
	Mention the new goal form.

doc/reference_manual.texi:
	Document the new goal form.

library/ops.m:
	Add "promise_equivalent_solution_sets" and "arbitrary" as new
	operators.

compiler/prog_item.m:
	Add a parse_tree representation of new constructs.

	Change the representation of goal forms in the parse tree to avoid
	using punctuation marks as function symbols, to avoid function symbols
	that need quoting, and to avoid ambiguity with hlds_goal_expr.

	Delete the obsolete if_then (no else) goal form.

compiler/hlds_goal.m:
	Provide a HLDS representation of the new constructs.

compiler/det_analysis.m:
	Implement the rules for processing the new constructs.

compiler/det_report.m:
	Implement the messages for the errors that can occur with the
	new constructs.

	Add quotes around `promise_equivalent_solutions' in an existing error
	message, for consistency.

compiler/prog_io_goal.m:
	Parse the new goal constructs.

compiler/add_clause.m:
compiler/hlds_out.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_warn.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/pd_util.m:
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_util.m:
compiler/saved_vars.m:
compiler/simplify.m:
	Conform to the changes to prog_item.m and hlds_goal.m.

tests/hard_coded/one_member.{m,exp}:
	New test case to test the proper functioning of the new construct.

tests/invalid/one_member.{m,err_exp}:
	New test case to test the kinds of errors that can occur when using
	the new construct.

tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
	Enable the new test cases.

tests/invalid/promise_equivalent_solutions_test.err_exp:
	Expect quotes around an old construct name, after the change to
	det_report.m.
2006-03-21 22:25:39 +00:00
Julien Fischer
9d8ca0ad37 Remove residual parts of the Aditi backend that weren't deleted the other day.
Estimated hours taken: 1.5
Branches: main

Remove residual parts of the Aditi backend that weren't deleted the other day.

configure.in:
Mmake.common.in:
	Remove support for enabling the Aditi backend.

runtime/mercury_aditi.h:
	Remove this file.

runtime/Mmakefile:
runtime/mercury.h:
runtime/mercury_imp.h:
runtime/mercury_ho_call.[ch]:
runtime/mercury_wrapper.[ch]:
	Delete support for Aditi in the runtime.

scripts/Mmake.rules:
scripts/Mmake.vars.in:
scripts/c2init.in:
scripts/parse_ml_options.sh-subr.in:
	Remove mmake support for building .rlo files, etc.

util/mkinit.c:
	Remove Aditi specific code.

compiler/bytecode_data.m:
compiler/closure_analysis.m:
compiler/code_model.m:
compiler/compile_target_code.m:
compiler/det_analysis.m:
compiler/handle_options.m:
compiler/hlds_goal.m:
compiler/hlds_module.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/mercury_to_mercury.m:
compiler/mlds_to_gcc.m:
compiler/modecheck_call.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/options.m:
compiler/prog_data.m:
compiler/prog_foreign.m:
compiler/prog_mode.m:
compiler/prog_type.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/term_errors.m:
compiler/unify_proc.m:
mdbcomp/prim_data.m:
	Remove residual support for Aditi.

library/ops.m:
	Remove the 'aditi_bottom_up' and 'aditi_top_down' operators from the
	ops table.

doc/reference_manual.texi:
doc/user_guide.texi:
	Delete the sections on the Aditi interface.

extras/aditi/*:
	Delete this.
2006-02-24 07:11:21 +00:00
Zoltan Somogyi
5b8f96f61d Prepare for an extension of promise_equivalent_solutions that will allow us
Estimated hours taken: 5
Branches: main

Prepare for an extension of promise_equivalent_solutions that will allow us
to better handle values of user-defined types. The problem is that currently,
the deconstruction of a value of such a type can be followed only by code that
cannot fail, otherwise the cc_multi deconstruction is not in the required
single-solution context. If the following code is naturally semidet, this
can be worked around by turning it into det code returning a maybe and testing
the maybe outside the promise_equivalent_solutions, but this is inefficient,
and in any case it does not generalize to nondet code without even more
horrendous inefficiency and inconvenience. (You have to create a nondet closure
and call it outside the promise_equivalent_solutions.)

The solution I came up with is something is to have a construct that contains

	- a list of deconstructions on types with user-defined equality,
	- a goal, and
	- the list of outputs of that goal.

The idea is that this would be transformed into a conjunction of the first and
second items, and wrapped inside a special kind of conj that provides a scope
for the implicit promise, which is that the set of solutions of the goal in
the second item doesn't depend on what concrete terms the deconstructions
in the first item return out of the set of concrete terms they *could* return.
The deconstructions in the first item would be marked to tell determinism
analysis to effectively ignore the fact that they involve user-defined
equality.

The actual addition of that construct is left for a future change, after we
agree on the syntax.

compiler/hlds_goal.m:
	Generalize the existing promise_equivalent_solutions scope to a
	promise_solutions scope with a flag that says whether in the source
	code it was originally the existing "promise_equivalent_solutions"
	construct or the new construct (which doesn't exist yet, but is
	indicated by the symbol "same_solutions" for now).

	Replace the conj and par_conj hlds_goal_exprs with a single goal
	expression: conj with an additional argument which is either plain_conj
	or parallel_conj. This was part of an earlier design in which a third
	kind of disjunction took the role now assigned to the new kind of
	promise_solutions scope, but turned out to be a good idea anyway,
	since in many places the compiler does treat the two kinds of
	conjunctions the same. This part of the change is responsible for the
	fact that this change results in a net *reduction* of about 40 lines.

	Move the most frequently used kinds of goal expressions to the front
	of the type declaration to allow the compiler to make better decisions
	about tag allocation.

	Add the goal marker we will add to the deconstructions in the first
	item.

	Replace the true_goal and fail_goal predicates with functions to make
	them easier to use, and rename their variants that take a context
	argument to avoid unnecessary ambiguity.

compiler/*.m:
	Conform to the change in hlds_goal.m.

	Misc changes to make code more robust, e.g. replacing semidet
	predicates on goal expressions with functions returning bool.

	Misc cleanups, e.g. removal of unnecessary module qualifications
	that made lines too long, renaming predicates whose names include
	"disj" if they are also used to process parallel conjunctions (since in
	both parallel conjunctions and in disjunctions the goals are
	independent), and turning semidet predicates that switch on goal
	expressions into bool functions (to make similar changes more rebust
	in the future).
2006-02-24 05:49:43 +00:00
Zoltan Somogyi
5af71b60ac Remove support for the Aditi backend. It is a pain to have to update it every
Estimated hours taken: 2
Branches: main

Remove support for the Aditi backend. It is a pain to have to update it every
time a data structure changes when we don't see any benefit from it, and its
presence makes compilation of the compiler directory take about 10% longer
(since the Aditi backend modules are roughly 10% of the code in the compiler
directory). Deleting the Aditi-specific data structures from the HLDS should
also speed up compilation a little bit.

I have spoken to Rao and he is fine with this step.

Aditi users, if there are any, can continue to use the Aditi support in
release 0.12.*. I also tagged the last version on the trunk to support aditi
with the name "last_aditi". The need for modifications in this Aditi support
is likely to be very rare to nonexistent, if the recent past is any guide:
the Aditi backend hasn't seen a nontrivial modification in a year or more.

This diff removes a net 31492 lines.

compiler/add_aditi.m:
compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/context.m:
compiler/dnf.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/rl.m:
compiler/rl_analyse.m:
compiler/rl_block.m:
compiler/rl_block_opt.m:
compiler/rl_code.m:
compiler/rl_dump.m:
compiler/rl_exprn.m:
compiler/rl_file.pp:
compiler/rl_gen.m:
compiler/rl_info.m:
compiler/rl_key.m:
compiler/rl_liveness.m:
compiler/rl_loop.m:
compiler/rl_opt.m:
compiler/rl_out.pp:
compiler/rl_relops.m:
compiler/rl_sort.m:
compiler/rl_stream.m:
	Remove these compiler modules, since they existed only to support the
	Aditi backend.

compiler/hlds_goal.m:
	Delete the Aditi-specific components of goals (e.g. the aditi-builtin
	kind of generic calls and Aditi-evaluated lambdas).

compiler/hlds_pred.m:
	Delete the Aditi-specific components of pred_infos.

compiler/prog_data.m:
	Delete the Aditi-specific items.

compiler/passes_aux.m:
	Don't worry about processing all procedures or just all non-Aditi
	procedures.

compiler/add_clause.m:
	Add a predicate from a deleted module that is now used only here.

compiler/*.m:
	Conform to the data structure changes above.

compiler/notes/*.html:
	Remove references to the Aditi backend.

tests/invalid/aditi.m:
tests/invalid/aditi_errors.err_exp:
tests/invalid/aditi_errors.m:
tests/invalid/aditi_private_builtin.m:
tests/invalid/aditi_state_errors.err_exp:
tests/invalid/aditi_state_errors.m:
tests/invalid/aditi_update_derived_relation.err_exp:
tests/invalid/aditi_update_derived_relation.m:
tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_mode_errors.err_exp:
tests/invalid/aditi_update_mode_errors.m:
tests/valid/aditi.m:
tests/valid/aditi_calls_mercury.m:
tests/valid/aditi_error_bug.m:
tests/valid/aditi_error_bug2.m:
tests/valid/aditi_error_bug3.m:
tests/valid/aditi_private_builtin.m:
tests/valid/aditi_query.m:
tests/valid/aditi_update.m:
tests/valid/base_relation.m:
tests/valid/base_relation2.m:
tests/valid/ite_to_disj.m:
	Remove these Aditi-specific tests.

tests/*/Mmakefile:
	Remove the references to these Aditi-specific tests.
2006-02-23 09:37:30 +00:00
Zoltan Somogyi
a1b8a22691 Break up a predicate whose code used to be 441(!) lines long
Estimated hours taken: 0.3
Branches: main

compiler/det_analysis.m:
	Break up a predicate whose code used to be 441(!) lines long
	into manageable pieces. There are no algorithmic changes.
2006-02-17 03:23:44 +00:00
Zoltan Somogyi
b819fbc0a6 Give the compiler the capability of detecting errors that manifest themselves
Estimated hours taken: 16
Branches: main

Give the compiler the capability of detecting errors that manifest themselves
as mismatches between the format string and the list of values to be printed
in calls to string.format and io.format.

This capability is controlled through two new options:

	--warn-known-bad-format-calls
	--warn-unknown-format-calls

The first (which will default to "on" once this change has bootstrapped)
controls whether the compiler emits warnings for statically known mismatches.
The second (which will default to "off") controls whether the compiler emits
warnings in cases where either the format string or the structure of the list
of values to be printed is not available statically to be checked.

NEWS:
	Mention the new capability.

compiler/options.m:
	Add the two new options.

doc/user_guide.texi:
	Document the new options.

compiler/format_call.m:
	New module to implement the new capability.

compiler/notes/compiler_structure.html:
	Document the new module.

compiler/check_hlds.m:
	Include the new module.

compiler/simplify.m:
	Invoke the new module if the procedure being processed contains calls
	to string.format or io.format.

	Fix an old bug: we could generate warnings or even errors when
	simplifying predicate bodies imported from other modules via
	intermodule optimization.

	Don't export get/set predicates that do not need to be exported.

compiler/det_report.m:
	Add new kinds of error specifications for the errors detected by the
	new module.

	Separate out the context of each error specification, in order
	to allow the error messages to be sorted by context; this makes
	the output much easier to read.

compiler/common.m:
compiler/det_analysis.m:
compiler/simplify.m:
	Conform to the change to det_report.m.

mdbcomp/prim_data.m:
	Add a utility function for forming the possibly qualified names of
	library modules (such as "io" and "string").

library/Mercury.options:
compiler/Mercury.options:
	Add the lines that disable the new checks in the modules that need them
	disabled. The new lines are commented out until installed compilers all
	understand them, at which point in time we will add the requirement to
	understand the option to configure.in.

compiler/fact_table.m:
compiler/mlds_to_il.m:
	Fix three bugs reported by the new check that have apparently escaped
	detection all this time.

library/rtti_implementation.m:
	Change some code to avoid a spurious warning from the new checks.

library/string.m:
	Rename a predicate to avoid an unnecessary and confusing overloading of
	its name.

	Replace __ with . as module qualifier connective.

compiler/handle_options.m:
library/pprint.m:
	Misc cleanups.

tests/invalid/string_format_bad.{m,err_exp}:
tests/invalid/string_format_unknown.{m,err_exp}:
	New test cases to test the new warnings.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
	Enable the new test cases.

tests/general/string_format_test*.exp*:
	Update any expected abort messages to expect . instead of __ as module
	qualifier connective.

tests/invalid/det_errors_cc.err_exp:
tests/invalid/erroneous_throw_promise.err_exp:
tests/warnings/simple_code.exp:
	Expect the same error messages in program context order.
2006-01-27 05:52:27 +00:00
Julien Fischer
5f589e98fb Various cleanups for the modules in the compiler directory.
Estimated hours taken: 4
Branches: main

Various cleanups for the modules in the compiler directory.  The are
no changes to algorithms except the replacement of some if-then-elses
that would naturally be switches with switches and the replacement of
most of the calls to error/1.

compiler/*.m:
	Convert calls to error/1 to calls to unexpected/2 or sorry/2 as
	appropriate throughout most or the compiler.

	Fix inaccurate assertion failure messages, e.g. identifying the
	assertion failure as taking place in the wrong module.

	Add :- end_module declarations.

	Fix formatting problems and bring the positioning of comments
	into line with our current coding standards.

	Fix some overlong lines.

	Convert some more modules to 4-space indentation.  Fix some spots
	where previous conversions to 4-space indentation have stuffed
	the formatting of the code up.

	Fix a bunch of typos in comments.

	Use state variables in more places; use library predicates
	from the sv* modules where appropriate.

	Delete unnecessary and duplicate module imports.

	Misc. other small cleanups.
2005-11-17 15:57:34 +00:00
Zoltan Somogyi
21685c9e22 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 6
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-11-04 03:41:09 +00:00
Zoltan Somogyi
f9fe8dcf61 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-10-28 02:11:03 +00:00
Zoltan Somogyi
b2012c0c0e Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8
Branches: main

compiler/*.m:
	Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
	and 'mer_mode'. This is to avoid the need to parenthesize these type
	names in some contexts, and to prepare for the possibility of a parser
	that considers those words to be reserved words.

	Rename some other uses of those names (e.g. as item types in
	recompilation.m).

	Delete some redundant synonyms (prog_type, mercury_type) for mer_type.

	Change some type names (e.g. mlds__type) and predicate names (e.g.
	deforest__goal) to make them unique even without module qualification.

	Rename the function symbols (e.g. pure, &) that need to be renamed
	to avoid the need to parenthesize them. Make their replacement names
	more expressive.

	Convert some more modules to four space indentation.

	Avoid excessively long lines, such as those resulting from the
	automatic substitution of 'mer_type' for 'type'.
2005-10-24 04:14:34 +00:00
Zoltan Somogyi
df0d9036cf Optimize calls that would be tail calls in Prolog but are followed by
Estimated hours taken: 40
Branches: main

Optimize calls that would be tail calls in Prolog but are followed by
construction unifications in Mercury: last call modulo construction.
For now, the optimization is available only for the LLDS backend.

compiler/lco.m:
	Turn this module from a placeholder to a real implementation
	of the optimization.

compiler/hlds_goal.m:
	Allow lco.m to attach to construction unifications a note that says
	that certain arguments, instead of being filled in by the unification,
	should have their addresses taken and stored in the corresponding
	variables.

	Group this note together with the note that asks for term size
	profiling to avoid an increase in the sizes of goals in the compiler
	in most cases.

compiler/hlds_pred.m:
	Provide a predicate for setting the name of a predicate after its
	creation. This functionality is used by lco.m.

	Extend the pred_transformation part of the pred_origin type to allow
	it to express that a procedure was created by lco.m.

	List the new primitive store_at_ref as a no-typeinfo builtin.

	Fix some problems with indentation.

compiler/layout_out.m:
	Handle the new pred_transformation.

compiler/unify_gen.m:
	When processing construction unifications that have the new feaure
	turned on, perform the requested action.

	Fix some departures from coding style. Shorten lines by deleting
	unnecessary module qualifications. Add some auxiliary predicates
	to make the code easier to read.

compiler/var_locn.m:
	Fix an earlier oversight: when materializing variables inside rvals
	and lvals, look inside memory references too. Previously, the omission
	didn't matter, since we didn't generate such references, but now we do.

	Fix some departures from coding style.

compiler/llds_out.m:
	Fix some old XXXs in code handling memory references. We didn't use to
	generate such references, but now we do.

	Move some functionality here from code_aux.m.

compiler/code_info.m:
	Provide some primitive operations needed by the new code in var_locn.m.

	Delete an unneeded predicate.

compiler/options.m:
	Rename the existing option optimize_constructor_last_call as
	optimize_constructor_last_call_accumulator, since that optimization
	is done by accumulator.m.

	Make optimize_constructor_last_call be the option that calls for the
	new optimization.

compiler/handle_options.m:
	Handle the implications of the new option.

compiler/mercury_compile.m:
	Invoke the lco module by its new interface.

librrary/private_builtin.m:
	Add a new primitive operation, store_at_ref, for use by the new
	optimization.

	Switch the module to four-space indentation.

compiler/add_clause.m:
	Comment out the warning for clauses for builtin, since this is needed
	to bootstrap the addition of the new builtin.

compiler/term_constr_initial.m:
	Handle the new builtin.

compiler/accumulator.m:
	Conform to the change in options.

compiler/builtin_ops.m:
	Provide a third template for builtins, for use by store_at_ref.

	Convert the file to four-space indentation.

compiler/call_gen.m:
	Generate code following the new builtin template.

compiler/rl_exprn.m:
	Minor changes to conform to the changes in builtin templates.

compiler/quantification.m:
	Minor changes to conform to the changes in construct unifications.

	Don't make the "get" predicates operating on quantification_infos
	to return the "new" quantification_info: it is always the same
	as the old one.

compiler/aditi_builtin_ops.m:
compiler/common.m:
compiler/deep_profiling.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/lambda.m:
compiler/magic_util.m:
compiler/ml_unify_gen.m:
compiler/modecheck_unify.m:
compiler/polymorphism.m:
compiler/size_prof.m:
	Minor changes to conform to the changes in construct unifications.

compiler/dependency_graph.m:
	Add a new predicate to recompute the dependency information,
	even if a previous (and possibly now inaccurate) version is present.

	Change the interface to make it clearer, by changing bools into types
	specific to the situation.

	Convert the file to four-space indentation.

compiler/mode_constraints.m:
	Minor changes to conform to the changes in dependency_graph.m.

compiler/code_aux.m:
	Delete this module. Half its functionality has been moved into
	llds_out.m, half to middle_rec.m (its only user).

compiler/goal_form.m:
	Move the predicates in this module that are used only by middle_rec.m
	to middle_rec.m.

	Convert the file to four-space indentation.

compiler/goal_util.m:
compiler/det_util.m:
	Move update_instmap from det_util to goal_util, since it is usefulness
	extends beyond determinism analysis.

	Convert det_util.m to four-space indentation.

compiler/middle_rec.m:
	Move here the code required only here from code_aux and goal_form.
	Update the moved code for the changes in construct unifications.
	The updates are specific to middle_rec.m: they wouldn't be of use
	to other modules. They basically say that any code that takes the
	addresses of fields cannot be handled by middle_rec.m.

compiler/code_gen.m:
compiler/det_analysis.m:
compiler/live_vars.m:
compiler/ll_backend.m:
compiler/loop_inv.m:
compiler/switch_detection.m:
compiler/switch_gen.m:
compiler/notes/compiler_design.html:
	Minor changes to conform to the deletion of code_aux.m and/or the
	movement of code from det_util to goal_util.m.

compiler/opt_debug.m:
	Print info for vars in rvals.

compiler/hlds_module.m:
	Convert a lambda to an explicit predicate to make some code easier to
	read.

	Switch the module to four-space indentation.
2005-09-13 04:56:20 +00:00
Zoltan Somogyi
6df9a05856 This diff cleans up a bunch of modules. It has no algorithmic changes
Estimated hours taken: 10
Branches: main

This diff cleans up a bunch of modules. It has no algorithmic changes
other than in the formatting of error messages.

compiler/error_util.m:
	Delete the obsolete predicate append_punctuation, since the suffix
	format component can now do more, and do it more easily.

compiler/goal_util.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/instmap.m:
compiler/const_prop.m:
	Change the argument order of some the predicates exported by these
	modules to make them easier to use with state variable syntax.

compiler/*.m:
	Convert a bunch of these modules to four space indentation, and fix
	departures from our coding style.

	Conform to the changed argument order above.

	Use suffixes instead of append_punctuation.

library/string.m:
	Add string.foldl2.

tests/invalid/circ_*.err_exp:
tests/warnings/unused_args_*.exp:
	Expect the updated error messages, which format sym_names consistently
	the same way as other messages.
2005-08-30 04:12:17 +00:00
Zoltan Somogyi
c17e9bc9f9 Convert this module to four-space indentation to reduce the number
Estimated hours taken: 1
Branches: main

compiler/det_analysis.m:
	Convert this module to four-space indentation to reduce the number
	of bad line breaks. Use consistent naming of the arguments of the
	main predicate of the module, and delete the arguments that turn out
	to be unused. Make the order of some arguments more logical. Give more
	expressive names to some variables.

compiler/pd_util.m
compiler/simplify.m
	Conform to the new argument order.
2005-08-19 08:35:57 +00:00
Zoltan Somogyi
a86edd19c8 Bring comment syntax up to date. Other minor style fixes.
Estimated hours taken: 0.5
Branches: main

compiler/det_analysis.m:
	Bring comment syntax up to date. Other minor style fixes.
2005-04-08 04:59:59 +00:00
Zoltan Somogyi
8b8b3b7d3f Replace the some() HLDS goal with a more general scope() goal, which can be
Estimated hours taken: 12
Branches: main

Replace the some() HLDS goal with a more general scope() goal, which can be
used not just for existential quantification but also for other purposes.

The main such purposes are new goal types that allow the programmer
to annotate arbitrary goals, and not just whole procedure bodies, with the
equivalents of promise_pure/promise_semipure and promise_only_solution:

	promise_pure ( <impure/semipure goal> )
	promise_semipure ( <impure goal> )

	promise_equivalent_solutions [OutVar1, OutVar2] (
		<cc_multi/cc_nondet goal that computed OutVar1 & OutVar2>
	)

Both are intended to be helpful in writing constraint solvers, as well as in
other situations.

doc/reference_manual.texi:
	Document the new constructs.

library/ops.m:
	Add the keywords of the new constructs to the list of operators.
	Since they work similarly to the "some" operator, they have the same
	precedence.

compiler/hlds_goal.m:
	Replace the some(Vars, SubGoal) HLDS construct, with its optional
	keep_this_commit attribute, with the new scope(Reason, SubGoal)
	construct. The Reason argument may say that this scope is an
	existential quantification, but it can also say that it represents
	a purity promise, the introduction of a single-solution context
	with promise_equivalent_solutions, or a decision by a compiler pass.

	It can also say that the scope represents a set of goals that all arise
	from the unraveling of a unification between a variable and a ground
	term. This was intended to speed up mode checking by significantly
	reducing the number of delays and wakeups, but the cost of the scopes
	themselves turned out to be bigger than the gain in modechecking speed.

	Update the goal_path_step type to refer to scope goals instead of just
	existential quantification.

compiler/prog_data.m:
	Add new function symbols to the type we use to represent goals in items
	to stand for the new Mercury constructs.

compiler/prog_io_goal.m:
	Add code to read in the new language constructs.

compiler/prog_io_util.m:
	Add a utility predicate for use by the new code in prog_io_goal.m.

compiler/make_hlds.m:
	Convert the item representation of the new constructs to the HLDS
	representation.

	Document how the from_ground_term scope reason would work, but do not
	enable the code.

compiler/purity.m:
	When checking the purity of goals, respect the new promise_pure and
	promise_semipure scopes. Generate warnings if such scopes are
	redundant.

compiler/det_analysis.m:
	Make the insides of promise_equivalent_solutions goals single solution
	contexts.

compiler/det_report.m:
	Provide mechanisms for reporting inappropriate usage of
	promise_equivalent_solutions goals.

compiler/instmap.m:
	Add a utility predicate for use by one of the modules above.

compiler/deep_profiling.m:
	Use one of the new scope reasons to prevent simplify from optimizing
	away commits of goals that have been made impure, instead of the old
	keep_this_commit goal feature.

compiler/modes.m:
	Handle from_ground_term scopes when present; for now, they won't be
	present, since make_hlds isn't creating them.

compiler/options.m:
	Add two new compiler options, for use by implementors only, to allow
	finer control over the amount of output one gets with --debug-modes.
	(I used them when debugging the performance of the from_ground_term
	scope reason.) The options are --debug-modes-minimal and
	--debug-modes-verbose.

compiler/handle_options.m:
	Make the options that are meaningful only in the presence of
	--debug-modes imply --debug-modes, since this allows more convenient
	(shorter) invocations.

compiler/mode_debug.m:
	Respect the new options when deciding how much data to print
	when debugging of the mode checking process is enabled.

compiler/switch_detect.m:
	Rename a predicate to make it differ from another predicate by more
	than just its arity.

compiler/passes_aux.m:
	Bring this module up to date with our current style guidelines,
	by using state variable syntax where appropriate.

compiler/*.m:
	Minor changes to conform to the change in the HLDS and/or parse tree
	goal type.

mdbcomp/program_representation.m:
	Rename the some goal to the scope goal, and the same for path steps,
	to keep them in sync with the HLDS.

browser/declarative_tree.m:
	Conform to the change in goal representations.

tests/hard_coded/promise_equivalent_solutions_test.{m,exp}:
	A new test case to test the handling of the
	promise_equivalent_solutions construct.

tests/hard_coded/Mmakefile:
	Enable the new test.

tests/hard_coded/purity/promise_pure_test.{m,exp}:
	A new test case to test the handling of the promise_pure and
	promise_semipure constructs.

tests/hard_coded/purity/Mmakefile:
	Enable the new test.

tests/invalid/promise_equivalent_solutions.{m,err_exp}:
	A new test case to test the error messages for improper use of the
	promise_pure and promise_semipure constructs.

tests/invalid/Mmakefile:
	Enable the new test.
2005-03-24 05:34:41 +00:00
Zoltan Somogyi
c08ca7fbc8 Import only one module per line in the modules of the compiler
Estimated hours taken: 3
Branches: main

compiler/*.m:
	Import only one module per line in the modules of the compiler
	where my previous diff did not already do so.

	Misc other cleanups.

	Where relevant, use the new mechanism in tree.m.

compiler/tree.m:
	Fix a performance problem I noticed while update :- import_module
	items. Instead of supplying a function to convert lists of trees
	to a tree, make the tree data structure able to hold a list of
	subtrees directly. This reduces the number of times where we have to
	convert list of trees to trees that are sticks just to stay within
	the old definition of what a tree is.
2005-03-24 02:00:43 +00:00
Julien Fischer
51b3ce2bab Catch errors concerning pragma export and model_non code
Estimated hours taken: 3
Branches: main

Catch errors concerning pragma export and model_non code
earlier than we do at the moment.  Currently, we just generate
#error directives in the C code and let the C preprocessor
report the error.

compiler/make_hlds.m:
	Emit an error message if pragma export is used on a
	procedure that has a declared determinism of multi
	or nondet.

compiler/det_analysis.m:
compiler/det_report.m:
	As above, but handle the case where the determinism
	needs to be inferred.

compiler/export.m:
	Abort rather than trying to generate code for model_non
	pragma exports.

tests/invalid/Mmakefile:
tests/invalid/invalid_export_detism.err_exp:
tests/invalid/invalid_export_detism.m:
	Test case for the above.
2005-01-06 04:30:55 +00:00
Julien Fischer
6ce720be87 Add the foreign proc. attribute `will_not_throw_exception'.
Estimated hours taken: 6
Branches: main

Add the foreign proc. attribute `will_not_throw_exception'.
This allows the user to promise the exception analysis that
foreign procs that do not have determinism erroneous and make
calls back to Mercury will not throw an exception.

The behaviour for erroneous foreign procs and those that do
not make calls back to Mercury is unchanged.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
	Handle the new attribute.

compiler/exception_analysis.m:
	If the user has provided the `will_not_throw_exception'
	attribute on a foreign proc that makes calls back to
	Mercury then set then have the exception analysis
	take account of this information.

	Fix a typo.

compiler/det_analysis.m:
compiler/det_report.m:
	Emit an error if the `will_not_throw_exception'
	attribute is used on foreign procs. that have
	been declared erroneous.

doc/reference_manual.texi:
	Mention the new foreign proc attribute.

tests/term/Mmakefile:
tests/term/Mercury.options:
tests/term/promise_no_throw_exception.m:
tests/term/promise_no_throw_exception.trans_opt_exp:
tests/invalid/Mmakefile:
tests/invalid/erroneous_promise_throw.m:
tests/invalid/erroneous_proimse_throw.err_exp:
	Test cases for the above.

vim/syntax/mercury.vim:
	Highlight the annotation appropriately.
2004-12-10 07:03:45 +00:00
Zoltan Somogyi
b2961048d8 Fix a problem reported by Ralph.
Estimated hours taken: 0.3
Branches: main

Fix a problem reported by Ralph.

compiler/det_analysis.m:
	Complain about bad determinisms for predicates with I/O states only if
	the predicate is declared with a bad determinism or doesn't have any
	declared determinism. Don't complain if the declared determinism is OK
	even if the inferred determinism isn't, since in that case the root of
	the problem lies elsewhere, and other error messages will point it out.

tests/invalid/magic_box.err_exp:
	Update the expected output of this test case.
2004-06-24 07:57:44 +00:00
Zoltan Somogyi
c219dc8b16 Fix a bug caught by the nightly tests. The cause of the bug is described
Estimated hours taken: 3
Branches: main

Fix a bug caught by the nightly tests. The cause of the bug is described
in the following comment in the cut down test case:

% This code is a cut down version of merge_key_ranges_2 in rl_key.m.
% It is a regression test; the 21 June 2004 version of the compiler got
% a compiler abort when compiling this code with deep profiling enabled.
%
% The problem had several causes that had all to be present.
%
% 1. The inlined code of less_or_equal contains a call. Deep profiling inserts
%    prepare_for_normal_call before that call, making it impure.
%
% 2. The body of less_or_equal isn't a complete switch in any argument, so
%    switch detection leaves a disjunction in it.
%
% 3. The inlining of less_or_equal in merge_key_ranges_2 *after* the initial
%    semantic checks causes the second run of simplify to modify the code,
%    removing the redundant check of the second argument of less_or_equal in
%    the second clause. This causes simplify to rerun determinism analysis.
%    (If the inlining is done in the source code, the simplification will have
%    been done in the first run of simplify, and simplify won't find any
%    improvements to do after the deep profiling transformation.)
%
% 4. When determinism analysis looks at the inlined disjunction, it disregards
%    the fact that it has no outputs because it is impure.
%
% The original symptom required -O5 to inline the relevant call in rl_key.m.
% We mark the predicate with pragma inline to force the problem, if present,
% to appear also at lower optimization levels.

The fix is to alter the behavior of determinism analysis.

compiler/det_analysis.m:
	When the new goal feature not_impure_for_determinism is present on a
	goal, ignore the impurity of the goal when computing its determinism.

compiler/deep_profiling.m:
	Add the new feature when making pure goals impure. For goals that were
	impure to begin with, do not add the feature. In both cases, the goal
	is to get determinism analysis to get the same result as it would get
	without the deep profiling transformation.

compiler/hlds_goal.m:
	Add the new goal feature, and add predicates for adding and removing
	more than one feature at a time.

compiler/saved_vars.m:
	Minor diff to handle the new feature.

tests/valid/impure_detism.m:
	New regression test case for this bug.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
	Enable the new test case, and specify the test options.

	Put test case lists into sorted order.
2004-06-22 08:54:50 +00:00
Zoltan Somogyi
885fd4a387 Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12
Branches: main

Remove almost all dependencies by the modules of parse_tree.m on the modules
of hlds.m. The only such dependencies remaining now are on type_util.m.

compiler/hlds_data.m:
compiler/prog_data.m:
	Move the cons_id type from hlds_data to prog_data, since several parts
	of the parse tree data structure depend on it (particularly insts).
	Remove the need to import HLDS modules in prog_data.m by making the
	cons_ids that refer to procedure ids refer to them via a new type
	that contains shrouded pred_ids and proc_ids. Since pred_ids and
	proc_ids are abstract types in hlds_data, add predicates to hlds_data
	to shroud and unshroud them.

	Also move some other types, e.g. mode_id and class_id, from hlds_data
	to prog_data.

compiler/hlds_data.m:
compiler/prog_util.m:
	Move predicates for manipulating cons_ids from hlds_data to prog_util.

compiler/inst.m:
compiler/prog_data.m:
	Move the contents of inst.m to prog_data.m, since that is where it
	belongs, and since doing so eliminates a circular dependency.
	The separation doesn't serve any purpose any more, since we don't
	need to import hlds_data.m anymore to get access to the cons_id type.

compiler/mode_util.m:
compiler/prog_mode.m:
compiler/parse_tree.m:
	Move the predicates in mode_util that don't depend on the HLDS to a new
	module prog_mode, which is part of parse_tree.m.

compiler/notes/compiler_design.m:
	Mention prog_mode.m, and delete the mention of inst.m.

compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Move the predicates that depend on HLDS out of mercury_to_mercury.m
	to hlds_out.m. Export from mercury_to_mercury.m the predicates needed
	by the moved predicates.

compiler/hlds_out.m:
compiler/prog_out.m:
	Move predicates for printing parts of the parse tree out of hlds_out.m
	to prog_out.m, since mercury_to_mercury.m needs to use them.

compiler/purity.m:
compiler/prog_out.m:
	Move predicates for printing purities from purity.m, which is part
	of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use
	them.

compiler/passes_aux.m:
compiler/prog_out.m:
	Move some utility predicates (e.g. for printing progress messages) from
	passes_aux.m to prog_out.m, since some predicates in submodules of
	parse_tree.m need to use them.

compiler/foreign.m:
compiler/prog_data.m:
	Move some types from foreign.m to prog_data.m to allow the elimination
	of some dependencies on foreign.m from submodules of parse_tree.m.

compiler/*.m:
	Conform to the changes above, mostly by updating lists of imported
	modules and module qualifications. In some cases, also do some local
	cleanups such as converting predicate declarations to predmode syntax
	and fixing white space.
2004-06-14 04:17:03 +00:00
Zoltan Somogyi
7bf0cd03af Reduce the overhead of all forms of tabling by eliminating in many cases
Estimated hours taken: 32
Branches: main

Reduce the overhead of all forms of tabling by eliminating in many cases
the overhead of transferring data across the C/Mercury boundary. These
involve lots of control transfers as well as assignments to and from
Mercury abstract machine registers, which are not real machine registers
on x86 machines. Benchmarking in Uppsala revealed this overhead to be
a real problem.

The way we do that is by changing the tabling transformation so that instead
of generating sequences of calls to predicates from library/table_builtin.m,
we generate sequences of calls to C macros from runtime/mercury_tabling_pred.h,
and emit the resulting code string as the body of a foreign_proc goal.
(The old transformation is still available via a new option,
--no-tabling-via-extra-args.)

Since the number of inputs and outputs of the resulting C code sequences
are not always fixed (they can depend on the number of input or output
arguments of predicate being transformed), implementing this required
adding to foreign_procs a new field that allows the specification of extra
arguments to be passed to and from the given foreign code fragment. For now,
this mechanism is implemented only by the C backends, since it is needed
only by the C backends. (We don't support yet tabling on other backends.)

To simplify the new implementation of the field on foreign_procs, consolidate
three existing fields into one. Each of these fields was a list with one
element per argument, so turning them into a single list with a combined record
per argument should also improve reliability, since it reduces the likelyhood
of updates leaving the data structure inconsistent.

The goal paths of components of a tabled predicate depend on whether
-no-tabling-via-extra-args was specified. To enable the expected outputs
of the debugger test cases testing tabling, we add a new mdb command,
goal_paths, that controls whether goal paths are printed by the debugger
at events, and turn off the printing of events in the relevant test cases.

Also, prepare for a future change to optimize the trie structure for
user-defined types by handling type_infos (and once we support them,
typeclass_infos) specially.

compiler/table_gen.m:
	Change the tabling transformation along the lines described above.

	To allow us to factor out as much of the new code as possible,
	we change the meaning of the call_table_tip variable for minimal
	model subgoals: instead of the trie node at the end of the answer
	table, it is not now the subgoal reachable from it. This change
	has no effect as yet, because we use call_table_tip variables
	only to perform resets across retries in the debugger, and we
	don't do retries across calls to minimal model tabled predicates.

	Put predicates into logical groups.

library/table_builtin.m:
runtime/mercury_tabling_preds.h:
	When the new transformations in table_gen.m generate foreign_procs
	with variable numbers of arguments, the interfaces of those
	foreign_procs often do not match the interfaces of the existing
	library predicates at their core: they frequently have one more
	or one fewer argument. To prevent any possible confusion, in such
	cases we add a new variant of the predicate. These predicates
	have the suffix _shortcut in their name. Their implementations
	are dummy macros that do nothing; they serve merely as placeholders
	before or after which the macros that actually do the work are
	inserted.

	Move the definitions of the lookup, save and restore predicates
	into mercury_tabling_preds.h. Make the naming scheme of their
	arguments more regular.

runtime/mercury_minimal_model.c:
runtime/mercury_tabling_preds.h:
	Move the definition of a predicate from mercury_minimal_model.c
	to mercury_tabling_preds.h, since the compiler now needs to be
	able to generate an inlined version of it.

compiler/hlds_goal.m:
	Replace the three existing fields describing the arguments of
	foreign_procs with one, and add a new field describing the extra
	arguments that may be inserted by table_gen.m.

	Add utility predicates for processing the arguments of foreign_procs.

	Change the order of some existing groups of declarations make it
	more logical.

compiler/hlds_pred.m:
runtime/mercury_stack_layout.h:
	Extend the data structures recording the structure of tabling tries
	to allow the representation of trie steps for type_infos and
	typeclass_infos.

runtime/mercury_tabling_macros.c:
	Fix a bug regarding the tabling of typeclass_infos, which is now
	required for a clean compile.

compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
	Modify the generation of code for foreign_procs to handle extra
	arguments, and to conform to the new data structures for foreign_proc
	arguments.

compiler/llds.m:
	The tabling transformations can now generate significantly sized
	foreign_procs bodies, which the LLDS code generator translates to
	pragma_c instructions. Duplicating these by jump optimization
	may lose more by worsening locality than it gains in avoiding jumps,
	so we add an extra field to pragma_c instructions that tells jumpopt
	not to duplicate code sequences containing such pragma_cs.

compiler/jumpopt.m:
	Respect the new flag on pragma_cs.

compiler/goal_util.m:
	Add a predicate to create foreign_procs with specified contents,
	modelled on the existing predicate to create calls.

	Change the order of the arguments of that existing predicate
	to make it more logical.

compiler/polymorphism.m:
	Conform to the new definition of foreign_procs. Try to simplify
	the mechanism for generating the type_info and typeclass_info
	arguments of foreign_proc goals, but it is not clear that this
	code is even ever executed.

compiler/aditi_builtin_ops.m:
compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/dnf.m:
compiler/dupelim.m:
compiler/equiv_type_hlds.m:
compiler/exprn_aux.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/frameopt.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/higher_order.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/ite_gen.m:
compiler/layout_out.m:
compiler/livemap.m:
compiler/liveness.m:
compiler/llds_out.m:
compiler/loop_inv.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mark_static_terms.m:
compiler/middle_rec.m:
compiler/modes.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/pd_cost.m:
compiler/prog_rep.m:
compiler/purity.m:
compiler/quantification.m:
compiler/reassign.m:
compiler/rl_exprn.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeed_code.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Conform to the new definition of foreign_procs, pragma_cs and/or
	table trie steps, or to changed argument orders.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/lco.m:
compiler/module_util.m:
compiler/opt_util.m:
compiler/stack_opt.m:
compiler/trans_opt.m:
	Conform to the new definition of foreign_procs.

	Bring these modules up to date with our current code style guidelines,
	using predmode declarations, state variable syntax and unification
	expressions as appropriate.

compiler/mercury_compile.m:
	Conform to the changed argument order of a predicate in trans_opt.m.

compiler/options.m:
	Add the --no-tabling-via-extra-args option, but leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
	Document --no-tabling-via-extra-args option, though leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
doc/mdb_categories:
	Document the new goal_paths mdb command.

trace/mercury_trace_internals.c:
	Implement the new goal_paths mdb command.

tests/debugger/completion.exp:
	Conform to the presence of the goal_paths mdb command.

tests/debugger/mdb_command_test.inp:
	Test the existence of documentation for the goal_paths mdb command.

tests/debugger/print_table.{inp,exp*}:
tests/debugger/retry.{inp,exp*}:
	Use the goal_paths command to avoid having the expected output
	depend on the presence or absence of --tabling-via-extra-args.

tests/tabling/table_foreign_output.{m,exp}:
	Add a new test case to test the save/restore of arguments of foreign
	types.

tests/tabling/Mmakefile:
	Enable the new test case.

tests/tabling/test_tabling:
	Make this script more robust.

	Add an option for testing only the standard model forms of tabling.
2004-06-07 09:07:23 +00:00
Zoltan Somogyi
bc56e927b6 Detect when a predicate has a pair of I/O states but isn't det or cc_multi.
Estimated hours taken: 6
Branches: main

Detect when a predicate has a pair of I/O states but isn't det or cc_multi.
Improve the generation of determinism error messages.

compiler/det_analysis.m:
	Detect when a predicate has a pair of I/O states but isn't det or
	cc_multi.

	Factor out some common code.

compiler/det_report.m:
	Add the new error type for predicates with I/O states.

	Use error_util much more extensively to generate error messages.

compiler/hlds_out.m:
	For several existing predicates that write out various HLDS
	constructs, provide versions that return representations of those
	constructs as strings or as error_util pieces, for use by det_report.m.
	Redefine the old predicates as simply printing the output of the new
	predicates where relevant, to avoid code duplication.

compiler/error_util.m:
	When describing a predicate name, specify whether we want to module
	qualify the name or not. The intention is that when generating a kind
	of error message which can only be generated for predicates defined
	in the current module, the module prefix should be omitted in the
	interest of clarity.

compiler/accumulator.m:
compiler/dead_proc_elim.m:
compiler/magic_util.m:
compiler/table_gen.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/typecheck.m:
	Conform to the changes in error_util.m.

compiler/globals.m:
	Reorder arguments to allow the use of state variable notation.

compiler/handle_globals.m:
compiler/mercury_compile.m:
compiler/source_file_map.m:
	Conform to the changed argument order in globals.m.

tests/invalid/aditi_update_errors.err_exp:
tests/invalid/errors2.err_exp2:
tests/invalid/external.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/missing_det_decls.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_syntax.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp:
tests/invalid/prog_io_erroneous.err_exp2:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/state_vars_test1.err_exp:
tests/invalid/state_vars_test2.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/typeclass_mode.err_exp:
tests/invalid/types.err_exp2:
tests/invalid/undef_mode_and_no_clauses.err_exp:
tests/recompilation/typeclass_method_pragma_r.err_exp.2:
tests/warnings/ambiguous_overloading.exp:
tests/warnings/duplicate_call.exp:
tests/warnings/duplicate_const.exp:
tests/warnings/infinite_recursion.exp:
tests/warnings/simple_code.exp:
tests/warnings/warn_dead_procs.exp:
tests/warnings/warn_stubs.exp:
	Update these files to expect the better error messages we now generate.
2004-05-14 08:40:33 +00:00
Zoltan Somogyi
ff33291e6d Fix a bug in my cleanup of this module that was detected by a debug
Estimated hours taken: 0.2
Branches: main

compiler/det_analysis.m:
	Fix a bug in my cleanup of this module that was detected by a debug
	grade bootcheck (the non-debug grade bootcheck succeeded).

tests/hard_coded/cc_and_non_cc_test.m:
	Document that this test case (the one that detected the bug) should
	be compiled with --no-inlining, to enable the detection of such bugs
	in all grades, not just those that turn off inlining.

tests/hard_coded/Mercury.options:
	Specify --no-inlining for cc_and_non_cc_test.
2004-04-08 03:51:46 +00:00
Zoltan Somogyi
ff60134ee9 Bring these modules up to our current coding standards.
Estimated hours taken: 8
Branches: main

analysis/analysis.m:
browser/browse.m:
compiler/accumulator.m:
compiler/assertion.m:
compiler/atsort.m:
compiler/c_util.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_model.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/dead_proc_elim.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/export.m:
compiler/fact_table.m:
compiler/follow_code.m:
compiler/graph_colour.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/ml_tailcall.m:
compiler/ml_unify_gen.m:
compiler/mmc_analysis.m:
compiler/mode_errors.m:
compiler/passes_aux.m:
compiler/post_typecheck.m:
compiler/size_prof.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_errors.m:
compiler/transform_llds.m:
compiler/type_util.m:
compiler/unify_gen.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Bring these modules up to our current coding standards. Use predmode
	declarations and state variable syntax where relevant. Reorder
	arguments where this is needed for the use state variables. Make the
	orders of predicate definitions correspond to the order of their
	declarations. Replace some overly large lambda expressions with named
	predicates. Convert some predicates to functions where this makes
	their use more convenient. Use field access notation where convenient.
	Fix any inconsistent indentation. Remove module prefixes on predicate
	names where this is necessary to allow sane indentation.

	In several places, use predicates from error_util.m to print error
	messages. Apart from this, there are no changes in algorithms.

	In some places, conform to the changes below.

compiler/error_util.m:
compiler/hlds_error_util.m:
	Add new variants of existing predicates for use in some of the
	changed modules above.

compiler/hlds_out.m:
	Add some functions to convert values of some HLDS types as strings,
	for use in preparing the arguments of the new calls to predicates in
	error_util.m. Change the implementations of the predicates that print
	values of those types to call those functions instead of allowing
	code duplication.

compiler/llds.m:
	Add some field names to allow use of field updates where relevant.

tests/invalid/assert_in_interface.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/tricky_assert1.err_exp:
	Update the expected outputs of these test cases to allow for them being
	generated by error_util.m, and hence being better formatted than
	before.
2004-04-05 05:07:49 +00:00
Zoltan Somogyi
44f001e26f Fix an overly strong sanity check, at least temporarily.
Estimated hours taken: 1
Branches: main

compiler/det_analysis.m:
	Fix an overly strong sanity check, at least temporarily.

tests/invalid/magicbox.m:
	Add the test case motivating that change.

tests/invalid/MMakefile
	Enable the new test.
2004-04-01 04:32:42 +00:00
Zoltan Somogyi
b39a3d855f This diff makes hlds_module.m and many callers of its predicates easier to read
Estimated hours taken: 6
Branches: main

This diff makes hlds_module.m and many callers of its predicates easier to read
and to maintain, but contains no changes in algorithms whatsoever.

compiler/hlds_module.m:
	Bring (most of) this module into line with our current coding
	standards. Use predmode declarations, functions, and state variable
	syntax when appropriate. (The 'most of' is because I left the part of
	the module dealing with predicate tables alone, not wishing to cause
	a conflict for Pete.)

	Reorder arguments of predicates where necessary for the use of state
	variable syntax, and where this improves readability.

	Replace old-style lambdas with new-style lambdas or with partially
	applied named procedures.

compiler/*.m:
	Conform to the changes in hlds_module.m. This mostly means using the
	new argument orders of predicates exported by hlds_module.m, and
	switching to state variable notation.

	Replace old-style lambdas with new-style lambdas or with partially
	applied named procedures in updated code.

	Replace unnecessary occurrences of four-space indentation with
	standard indentation in updated code.

library/list.m:
library/map.m:
library/tree234.m:
	Add list__foldl4 and map__foldl3, since in some compiler modules,
	state variable notation is more convenient (and the code more
	efficient) if we don't have to bundle up several data structures
	into a tuple just to iterate over them.

	Change the fold predicates to use state variable notation.

NEWS:
	Mention the new library functions.
2003-10-31 03:27:39 +00:00
Zoltan Somogyi
8693e293a2 This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4
Branches: main

This diff makes hlds_pred.m and many callers of its predicates easier to read
and to maintain, but contains no changes in algorithms whatsoever.

compiler/hlds_pred.m:
	Bring this module into line with our current coding standards.
	Use predmode declarations, functions, and state variable syntax
	when appropriate.

	Reorder arguments of predicates where necessary for the use of state
	variable syntax, and where this improves readability.

	Replace old-style lambdas with new-style lambdas or with partially
	applied named procedures.

	Standardize indentation.

compiler/*.m:
	Conform to the changes in hlds_pred.m. This mostly means using the
	new argument orders of predicates exported by hlds_pred.m. Where this
	is now conveniently possible, change predicates to use state
	variable notation.

	In some modules, using state variable notation required changing the
	orders of arguments in the module's top predicate.

compiler/passes_aux.m:
	Change the order of arguments in the calls this module makes to
	allow the callees to use state variable notation.

	Convert this module to state variable notation too.
2003-10-24 06:17:51 +00:00
Zoltan Somogyi
4f42c8e2b1 Improve the documentation of predicates checking for user-defined
Estimated hours taken: 0.2
Branches: main

compiler/type_util.m:
compiler/det_analysis.m:
	Improve the documentation of predicates checking for user-defined
	equality.
2003-05-29 09:19:44 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00