Commit Graph

42 Commits

Author SHA1 Message Date
Zoltan Somogyi
9ce35377f6 Fix a problem with the representation of goal paths for switches on unbounded
Estimated hours taken: 2
Branches: main

Fix a problem with the representation of goal paths for switches on unbounded
numbers of function symbols, such as ints, floats and strings. We used to
represent such switches as a negative number in the field representing the
number of function symbols in the switched-on type, but some parts of the
system weren't handling negative numbers specially, and they couldn't be
properly parsed back in anyway (since "-" was also the character separating
the case's ordinal number from this number).

mdbcomp/program_representation.m:
	Change the switch goal path step to use a maybe type to record the
	number of function symbols in the switched-on type, with a "no" meaning
	the type is unbounded. Update the goal path step printing and parsing
	code accordingly.

	Make the names of some other function symbols more expressive.

browser/declarative_execution.m:
	Conform to the change to program_representation.m.

compiler/goal_path.m:
compiler/deep_profiling.m:
compiler/unneeded_code.m:
	Update the code that creates goal path steps.

	In deep_profiling.m, fix an old bug: the two integers (case number,
	number of function symbols in switched-on type) were swapped.

	In deep_profiling.m, give a prefix to the field names of the main
	structure passed around, to try to make them unique.

tests/debugger/switch_on_unbounded.{m,inp,exp}:
	New test case to test this fix.

tests/debugger/Mmakefile:
	Enable the new test case.
2007-04-19 04:24:53 +00:00
Zoltan Somogyi
2bada9761f Eliminate some code duplication by unifying the two goal_path types have had
Estimated hours taken: 2
Branches: main

Eliminate some code duplication by unifying the two goal_path types have had
until now: one in mdbcomp/program_representation.m and compiler/hlds_goal.m,
which differed in only one detail (whether we record the total number of arms
in a switch). The new type is in program_representation.m, but with the
definition from goal_path.m.

Add a "step_" prefix to the function symbols of the goal_path_step type,
to avoid ambiguity with the hlds goals the steps describe.

Turn the predicates operating on goal_paths into functions for greater
convenience of use.

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

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

tests/debugger/*.exp:
	Expect the extra information now available for goal path steps
	describing switches.
2007-01-06 10:56:27 +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
Julien Fischer
b4c3bb1387 Clean up in unused module imports in the Mercury system detected
Estimated hours taken: 3
Branches: main

Clean up in unused module imports in the Mercury system detected
by --warn-unused-imports.

analysis/*.m:
browser/*.m:
deep_profiler/*.m:
compiler/*.m:
library/*.m:
mdbcomp/*.m:
profiler/*.m:
slice/*.m:
	Remove unused module imports.

	Fix some minor departures from our coding standards.

analysis/Mercury.options:
browser/Mercury.options:
deep_profiler/Mercury.options:
compiler/Mercury.options:
library/Mercury.options:
mdbcomp/Mercury.options:
profiler/Mercury.options:
slice/Mercury.options:
	Set --no-warn-unused-imports for those modules that are used as
	packages or otherwise break --warn-unused-imports, e.g. because they
	contain predicates with both foreign and Mercury clauses and some of
	the imports only depend on the latter.
2006-12-01 15:04:40 +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
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
Julien Fischer
e12ca34b2a Fix a bug reported by Peter Hawkins. The problem occurred with switches with
Estimated hours taken: 6
Branches: main, release

Fix a bug reported by Peter Hawkins.  The problem occurred with switches with
multiple arms that shared code.   Switch detection expands such arms by making
copies of the shared code.  Requantification then renames the variables in
these copies apart, but the new variables are not being entered into the RTTI
varmaps.   This leads to an assertion failure.

compiler/quantification.m:
 	Update the RTTI varmaps after renaming apart.  Failing to add any
 	freshly introduced variables into the RTTI varmaps makes them
 	inconsistent.

compiler/add_clause.m:
compiler/add_pragma.m:
compiler/cse_detection.m:
compiler/equiv_type_hlds.m:
compiler/follow_code.m:
compiler/hlds_clauses.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/lambda.m:
compiler/mode_constraints.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/tupling.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
 	Conform to the above change.

 	Minor formatting fixes.

tests/valid/Mmakefile:
tests/valid/hawkins_switch_bug.m:
 	Test case for the above.
2006-08-04 10:51:22 +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
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
be5b71861b Convert almost all the compiler modules to use . instead of __ as
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Convert almost all the compiler modules to use . instead of __ as
	the module qualifier.

	In some cases, change the names of predicates and types to make them
	meaningful without the module qualifier. In particular, most of the
	types that used to be referred to with an "mlds__" prefix have been
	changed to have a "mlds_" prefix instead of changing the prefix to
	"mlds.".

	There are no algorithmic changes.
2006-03-17 01:40:46 +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
Julien Fischer
45fdb6c451 Use expect/3 in place of require/2 throughout most of the
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Use expect/3 in place of require/2 throughout most of the
	compiler.

	Use unexpected/2 (or sorry/2) in place of error/1 in more
	places.

	Fix more dodgy assertion error messages.

	s/map(prog_var, mer_type)/vartypes/ where the latter is meant.
2005-11-28 04:11:59 +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
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
b54ab42d70 A simple tool for performing substitutions on the source files of the
Estimated hours taken: 0.5
Branches: main

tools/subst:
	A simple tool for performing substitutions on the source files of the
	compiler.

compiler/*.m:
	Change the names of the get predicates operating on module_infos to
	include "get" in the name, for uniformity. This was done mostly by
	the following sed script, with some manual cleanup afterwards to reduce
	excessive line lengths.

s/module_info_types/module_info_get_type_table/
s/module_info_set_types/module_info_set_type_table/
s/module_info_insts/module_info_get_inst_table/
s/module_info_set_insts/module_info_set_inst_table/
s/module_info_modes/module_info_get_mode_table/
s/module_info_set_modes/module_info_set_mode_table/
s/module_info_ctors/module_info_get_cons_table/
s/module_info_set_ctors/module_info_set_cons_table/
s/module_info_classes/module_info_get_class_table/
s/module_info_set_classes/module_info_set_class_table/
s/module_info_instances/module_info_get_instance_table/
s/module_info_set_instances/module_info_set_instance_table/
s/module_info_superclasses/module_info_get_superclass_table/
s/module_info_set_superclasses/module_info_set_superclass_table/
s/module_info_assertion_table/module_info_get_assertion_table/
s/module_info_exclusive_table/module_info_get_exclusive_table/
s/module_info_ctor_field_table/module_info_get_ctor_field_table/
s/module_info_name/module_info_get_name/
s/module_info_globals/module_info_get_globals/
s/module_info_contains_foreign_types/module_info_get_contains_foreign_types/
s/module_info_num_errors/module_info_get_num_errors/
s/module_info_type_ctor_gen_infos/module_info_get_type_ctor_gen_infos/
s/module_info_stratified_preds/module_info_get_stratified_preds/
s/module_info_unused_arg_info/module_info_get_unused_arg_info/
s/module_info_exception_info/module_info_get_exception_info/
s/module_info_type_spec_info/module_info_get_type_spec_info/
s/module_info_no_tag_types/module_info_get_no_tag_types/
s/module_info_analysis_info/module_info_get_analysis_info/
s/module_info_aditi_top_down_procs/module_info_get_aditi_top_down_procs/
2005-09-30 08:08:49 +00:00
Zoltan Somogyi
84bdb77414 Convert these modules to four-space indentation to reduce the number
Estimated hours taken: 1.5
Branches: main

compiler/det_report.m:
compiler/hlds_out.m:
compiler/llds.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
	Convert these modules to four-space indentation to reduce the number
	of bad line breaks. Fix some departures from our coding standards.

compiler/hlds_pred.m:
	Fix some formatting.
2005-08-15 07:18:31 +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
3c60c0e485 Change a bunch of modules to import only one module per line, even
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Change a bunch of modules to import only one module per line, even
	from the library.

compiler/mlds_to_il.m:
compiler/mlds_to_managed.m:
	Convert these modules to our current coding style. Use state variables
	where appropriate. Use predmode declarations where possible.
2005-03-22 06:40:32 +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
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
5d6fd3bd6f Reduce the dependence of earlier parts of the compiler on the later ones.
Estimated hours taken: 4
Branches: main

Reduce the dependence of earlier parts of the compiler on the later ones.
Unnecessary import_module declarations in top level modules such as hlds.m
cause unnecessary recompilations when adding new types in later modules,
such as submodules of ll_backend.m. This change reduces the number of such
unnecessary imports.

There are no changes in algorithms, only functionality being moved around.

compiler/code_model.m:
	Change this module from being a submodule of backend_libs.m to being a
	submodule of hlds.m, since nothing in it is dependent on any backend.

compiler/arg_info.m:
compiler/code_util.m:
	Change arg_info.m from being a submodule of ll_backend.m to being a
	submodule of hlds.m, since most of it is applicable to all current
	and foreseeable backends. Move the one exported predicate that is
	ll_backend dependent, and its support predicates, to code_util.m.

compiler/backend_libs.m:
compiler/ll_backend.m:
compiler/hlds.m:
	Update include_module declarations in accordance with the above.

compiler/prog_data.m:
compiler/term_util.m:
	Instead of defining two separate types for holding argument size and
	termination information, one including HLDS-specific information (in
	term_util.m) and one not (in prog_data.m), use a polymorphic type
	defined in prog_data.m and two monomorphic instances.

compiler/termination.m:
compiler/mercury_to_mercury.m:
	Change the predicates for writing out argument size and termination
	information to handle the polymorphic type (we don't need special
	handling of the monomorphic versions), and move them from termination.m
	to mercury_to_mercury.m, since this allows us to avoid some
	undesirable dependencies.

compiler/base_typeclass_info.m:
compiler/hlds_code_util.m:
	Move the predicate make_instance_string from base_typeclass_info.m
	to hlds_code_util.m, again because it allows us to remove some
	undesirable dependencies.

compiler/top_level.m:
compiler/backend_libs.m:
compiler/check_hlds.m:
compiler/hlds.m:
compiler/ll_backend.m:
compiler/parse_tree.m:
compiler/transform_hlds.m:
	Delete some import_module declarations of other top level modules
	in these top level modules. Some imports were totally unnecessary.
	Some imports were useful in only a small minority of submodules;
	those submodules now import the necessary top level modules directly.

	Move remaining import_module declarations to the implementation section
	where this is feasible.

	Where we still need to import modules we ideally shouldn't, note why.

compiler/*.m:
	Update imports of code_util and arg_info.

	In some cases, import top level modules no longer imported by the
	parent module.

	In some cases, delete unnecessary imports.
2004-03-23 10:52:14 +00:00
Zoltan Somogyi
a2bf36e49a This diff contains no changes in algorithms whatsoever.
Estimated hours taken: 4
Branches: main

This diff contains no changes in algorithms whatsoever.

browser/*.m:
compiler/*.m:
library/*.m:
	Replace old-style lambdas with new-style lambdas or with named
	procedures.
2003-11-05 03:17:49 +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
10cea48947 Remove unneeded parentheses from module name.
Estimated hours taken: 0.1
Branches: main

compiler/assertion.m:
compiler/inst.m:
	Remove unneeded parentheses from module name.

compiler/unneeded_code.m:
	Remove duplicate import.
2003-03-27 05:33:43 +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
Zoltan Somogyi
189b9215ae This diff implements stack slot optimization for the LLDS back end based on
Estimated hours taken: 400
Branches: main

This diff implements stack slot optimization for the LLDS back end based on
the idea that after a unification such as A = f(B, C, D), saving the
variable A on the stack indirectly also saves the values of B, C and D.

Figuring out what subset of {B,C,D} to access via A and what subset to access
via their own stack slots is a tricky optimization problem. The algorithm we
use to solve it is described in the paper "Using the heap to eliminate stack
accesses" by Zoltan Somogyi and Peter Stuckey, available in ~zs/rep/stackslot.
That paper also describes (and has examples of) the source-to-source
transformation that implements the optimization.

The optimization needs to know what variables are flushed at call sites
and at program points that establish resume points (e.g. entries to
disjunctions and if-then-elses). We already had code to compute this
information in live_vars.m, but this code was being invoked too late.
This diff modifies live_vars.m to allow it to be invoked both by the stack
slot optimization transformation and by the code generator, and allows its
function to be tailored to the requirements of each invocation.

The information computed by live_vars.m is specific to the LLDS back end,
since the MLDS back ends do not (yet) have the same control over stack
frame layout. We therefore store this information in a new back end specific
field in goal_infos. For uniformity, we make all the other existing back end
specific fields in goal_infos, as well as the similarly back end specific
store map field of goal_exprs, subfields of this new field. This happens
to significantly reduce the sizes of goal_infos.

To allow a more meaningful comparison of the gains produced by the new
optimization, do not save any variables across erroneous calls even if
the new optimization is not enabled.

compiler/stack_opt.m:
	New module containing the code that performs the transformation
	to optimize stack slot usage.

compiler/matching.m:
	New module containing an algorithm for maximal matching in bipartite
	graphs, specialized for the graphs needed by stack_opt.m.

compiler/mercury_compile.m:
	Invoke the new optimization if the options ask for it.

compiler/stack_alloc.m:
	New module containing code that is shared between the old,
	non-optimizing stack slot allocation system and the new, optimizing
	stack slot allocation system, and the code for actually allocating
	stack slots in the absence of optimization.

	Live_vars.m used to have two tasks: find out what variables need to be
	saved on the stack, and allocating those variables to stack slots.
	Live_vars.m now does only the first task; stack_alloc.m now does
	the second, using code that used to be in live_vars.m.

compiler/trace_params:
	Add a new function to test the trace level, which returns yes if we
	want to preserve the values of the input headvars.

compiler/notes/compiler_design.html:
	Document the new modules (as well as trace_params.m, which wasn't
	documented earlier).

compiler/live_vars.m:
	Delete the code that is now in stack_alloc.m and graph_colour.m.

	Separate out the kinds of stack uses due to nondeterminism: the stack
	slots used by nondet calls, and the stack slots used by resumption
	points, in order to allow the reuse of stack slots used by resumption
	points after execution has left their scope. This should allow the
	same stack slots to be used by different variables in the resumption
	point at the start of an else branch and nondet calls in the then
	branch, since the resumption point of the else branch is not in effect
	when the then branch is executed.

	If the new option --opt-no-return-calls is set, then say that we do not
	need to save any values across erroneous calls.

	Use type classes to allow the information generated by this module
	to be recorded in the way required by its invoker.

	Package up the data structures being passed around readonly into a
	single tuple.

compiler/store_alloc.m:
	Allow this module to be invoked by stack_opt.m without invoking the
	follow_vars transformation, since applying follow_vars before the form
	of the HLDS code is otherwise final can be a pessimization.

	Make the module_info a part of the record containing the readonly data
	passed around during the traversal.

compiler/common.m:
	Do not delete or move around unifications created by stack_opt.m.

compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/var_locn.m:
	Allow the code generator to delete its last record of the location
	of a value when generating code to make an erroneous call, if the new
	--opt-no-return-calls option is set.

compiler/code_gen.m:
	Use a more useful algorithm to create the messages/comments that
	we put into incr_sp instructions, e.g. by distinguishing between
	predicates and functions. This is to allow the new scripts in the
	tool directory to gather statistics about the effect of the
	optimization on stack frame sizes.

library/exception.m:
	Make a hand-written incr_sp follow the new pattern.

compiler/arg_info.m:
	Add predicates to figure out the set of input, output and unused
	arguments of a procedure in several different circumstances.
	Previously, variants of these predicates were repeated in several
	places.

compiler/goal_util.m:
	Export some previously private utility predicates.

compiler/handle_options.m:
	Turn off stack slot optimizations when debugging, unless
	--trace-optimized is set.

	Add a new dump format useful for debugging --optimize-saved-vars.

compiler/hlds_llds.m:
	New module for handling all the stuff specific to the LLDS back end
	in HLDS goal_infos.

compiler/hlds_goal.m:
	Move all the relevant stuff into the new back end specific field
	in goal_infos.

compiler/notes/allocation.html:
	Update the documentation of store maps to reflect their movement
	into a subfield of goal_infos.

compiler/*.m:
	Minor changes to accomodate the placement of all back end specific
	information about goals from goal_exprs and individual fields of
	goal_infos into a new field in goal_infos that gathers together
	all back end specific information.

compiler/use_local_vars.m:
	Look for sequences in which several instructions use a fake register
	or stack slot as a base register pointing to a cell, and make those
	instructions use a local variable instead.

	Without this, a key assumption of the stack slot optimization,
	that accessing a field in a cell costs only one load or store
	instruction, would be much less likely to be true. (With this
	optimization, the assumption will be false only if the C compiler's
	code generator runs out of registers in a basic block, which for
	the code we generate should be unlikely even on x86s.)

compiler/options.m:
	Make the old option --optimize-saved-vars ask for both the old stack
	slot optimization (implemented by saved_vars.m) that only eliminates
	the storing of constants in stack slots, and the new optimization.

	Add two new options --optimize-saved-vars-{const,cell} to turn on
	the two optimizations separately.

	Add a bunch of options to specify the parameters of the new
	optimizations, both in stack_opt.m and use_local_vars.m. These are
	for implementors only; they are deliberately not documented.

	Add a new option, --opt-no-return-cells, that governs whether we avoid
	saving variables on the stack at calls that cannot return, either by
	succeeding or by failing. This is for implementors only, and thus
	deliberately documented only in comments. It is enabled by default.

compiler/optimize.m:
	Transmit the value of a new option to use_local_vars.m.

doc/user_guide.texi:
	Update the documentation of --optimize-saved-vars.

library/tree234.m:
	Undo a previous change of mine that effectively applied this
	optimization by hand. That change complicated the code, and now
	the compiler can do the optimization automatically.

tools/extract_incr_sp:
	A new script for extracting stack frame sizes and messages from
	stack increment operations in the C code for LLDS grades.

tools/frame_sizes:
	A new script that uses extract_incr_sp to extract information about
	stack frame sizes from the C files saved from a stage 2 directory
	by makebatch and summarizes the resulting information.

tools/avg_frame_size:
	A new script that computes average stack frame sizes from the files
	created by frame_sizes.

tools/compare_frame_sizes:
	A new script that compares the stack frame size information
	extracted from two different stage 2 directories by frame_sizes,
	reporting on both average stack frame sizes and on specific procedures
	that have different stack frame sizes in the two versions.
2002-03-28 03:44:41 +00:00
Zoltan Somogyi
c980ee58d8 Split code_aux.m into two. The part that remains in code_aux.m needs stuff
Estimated hours taken: 1
Branches: main

Split code_aux.m into two. The part that remains in code_aux.m needs stuff
from the LLDS back end. The part that moves out (to the new file goal_form)
doesn't. This removes several unnecessary dependencies on the LLDS back end.

compiler/goal_form.m:
	The predicates from code_aux that test goals for having particular
	forms. It is part of the hlds module.

compiler/code_aux.m:
	Delete the predicates that moved to goal_form.m.

compiler/*.m:
	Fix module qualifications and module imports to account for the above
	change. In the process, sort module imports into groups.
2002-03-22 07:10:41 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00
Adrian Pellas-Rice
1c65d003f7 Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
Estimated hours taken: 4.5
Branches: main

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

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

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

        Added the functor shorthand to the goal_expr type.

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

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

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

:- type pragma_foreign_code_attributes
:- type pragma_foreign_proc_attributes

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

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

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

Implement pragma foreign_code for Managed C++.

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

tests/invalid/pragma_c_code_and_clauses1.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/warnings/singleton_test.exp:
	Update the tests to reflect the new error messages talking
	about :- pragma foreign_code rather than :- pragma c_code.
2000-11-17 17:48:52 +00:00
David Overton
82378c381b Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80

Allow polymorphic ground insts.  This change assumes that all inst
parameters in the mode declaration for a predicate or function are
constrained to be ground-shared.  This is a temporary measure until we
work out a nice syntax to allow the programmer to tell the compiler that
certain inst parameters may be treated as ground insts.  Since we don't
currently support unconstrained inst parameters anyway, this shouldn't
cause a problem.

	TODO:
		- Add syntax, something like `:- mode p(in(I)) <= ground(I).',
		  to specify that an inst parameter represents a ground inst.
		- Allow abstract ground insts that are treated in a similar
		  way to what we've done here with ground inst parameters.
		- Make mode checking more efficient (i.e. rewrite the mode
		  system).

compiler/inst.m:
	Add a new alternative for ground insts:
		`constrained_inst_var(inst_var)'.
	Define the type `inst_var_sub'.

compiler/inst_match.m:
	Change inst_matches_initial so that it:
		- handles constrained_inst_vars correctly;
		- returns the inst_var substitutions necessary for the call;
		- handles inst_matches_initial(ground(...), bound(...), ...)
		  properly (this requires knowing the type of the variable).

	  The last change has also been made for inst_matches_final
	  and inst_matches_binding.  However, the check is disabled for
	  now because, without alias tracking, the mode checker
	  becomes too conservative.

compiler/hlds_pred.m:
compiler/mode_info.m:
compiler/simplify.m:
compiler/det_util.m:
	Include the inst_varset in the proc_info, mode_info and simplify_info.
	Add a vartypes field to the det_info.
	Remove the vartypes field from the simplify_info since it is
	now in the det_info.
	Use record syntax for these data structures and their access predicates
	to make future changes easier.

compiler/prog_io.m:
	When processing pred and func mode declarations, convert all inst_var(V)
	insts to ground(shared, constrained_inst_var(V)).

compiler/prog_data.m:
compiler/hlds_data.m:
compiler/make_hlds.m:
compiler/mode_util.m:
	Use inst_vars instead of inst_params.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/unique_modes.m:
compiler/mode_util.m:
	When checking or recomputing initial insts of a call, build up
	an inst_var substitution (using the modified
	inst_matches_initial) and apply this to the final insts of the
	called procedure before checking/recomputing them.

compiler/mode_util.m:
	Make sure that recompute_instmap_delta recomputes the
	instmap_deltas for lambda_goals even when RecomputeAtomic = no.

compiler/type_util.m:
	Add a new predicate, type_util__cons_id_arg_types which
	nondeterministically returns the cons_ids and argument types for a
	given type.
	Add a new predicate type_util__get_consid_non_existential_arg_types
	which is the same as type_util__get_existential_arg_types except
	that it fails rather than aborting for existenially typed arguments.

compiler/accumulator.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/common.m:
compiler/continuation_info.m:
compiler/deforest.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/dnf.m:
compiler/follow_code.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/mercury_to_mercury.m:
compiler/modecheck_unify.m:
compiler/module_qual.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_io_util.m:
compiler/prog_rep.m:
compiler/saved_vars.m:
compiler/stack_layout.m:
compiler/table_gen.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Pass inst_varsets and types where needed.
	Changes to reflect change in definition of the inst data type.

compiler/inlining.m:
	Recompute the instmap deltas for a procedure after inlining.
	This bug showed up compiling tests/hard_coded/lp.m with
	inlining and deforestation turned on: deforestation was
	getting incorrect instmap deltas from inlining, causing
	the transformation to break mode-correctness.  It has only
	just shown up because of the added call to
	`inst_matches_initial' from within `recompute_instmap_delta'.

tests/invalid/Mmakefile:
tests/invalid/unbound_inst_var.m:
tests/invalid/unbound_inst_var.err_exp:
tests/valid/Mmakefile:
tests/valid/unbound_inst_var.m:
	Move the `unbound_inst_var' test case from `invalid' to `valid'
	and extend its coverage a bit.
2000-10-13 13:56:17 +00:00
Zoltan Somogyi
10a433374b Restore the clipping of instmap deltas to the nonlocals set, undoing most of
Estimated hours taken: 16

Restore the clipping of instmap deltas to the nonlocals set, undoing most of
a recent change of mine. (The general cleanup parts of that change, e.g.
added field names, stay.) The reason is that the previous diff changed the
clipping algorithm only where the instmap deltas were being originally
computed, whereas for completeness you also need to do this in places where
they are recomputed after optimizations such as deforestation, and doing so
would have required changes in several more parts of the compiler, which
would have been tedious to maintain.

Instead, I now use a different technique to solve the original problem.
This technique is to change liveness.m so that it considers the first
occurrence of any type(class)info variable to be a value giving occurrence
even if the variable is not referred to by the instmap delta of the goal.
This assumption is true in the current polymorphism design and in any
extension of it that I can foresee. Type(class)info variables will therefore
be born in the first goal that refers to them, even if they are not in the
nonlocal set of that goal. If there are any later references to variables
whose type is described in whole or in part by that typeinfo, the typeinfo
will die at the last such reference, otherwise it will die in the goal
in which it is born.

From now on, the only module of the compile which needs to worry about the
extension of the life of type(class)info variables beyond the goals referring
to them is liveness.m.

compiler/quantification.m:
compiler/mode_info.m:
compiler/mode_util.m:
	Reset the interfaces of quantification and mode checking to the old
	ones, which do not require knowing typeinfo_liveness and typeinfo
	varmaps.

compiler/modes.m:
compiler/unique_modes.m:
	Clip instmap deltas to the nonlocals, not the completed nonlocals.

compiler/hlds_goal.m:
	Add a utility pred which gets the nonlocals from a goal, not a
	goal_info.

compiler/liveness.m:
	Add special handling for type(class)info vars as described above.

compiler/accumulator.m:
compiler/cse_detection.m:
compiler/deforest.m:
compiler/follow_code.m:
compiler/higher_order.m:
compiler/lambda.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/unify_proc.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Use the reset interfaces of quantification and mode checking,
	and eliminate redundant local copies of goal_get_nonlocals.
2000-09-16 00:08:31 +00:00
Tyson Dowd
c192d50143 Add preliminary support for a new pragma:
Estimated hours taken: 15

Add preliminary support for a new pragma:

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

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

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

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

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

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

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

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

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

compiler/*.m:
	Update the rest of the compiler to handle these types.
	Make a few small changes to update variable names, predicate
	names and type names.
2000-08-09 07:48:04 +00:00
Zoltan Somogyi
891b89e650 Make sure that all parts of the compiler use a consistent idea of which
Estimated hours taken: 4

Make sure that all parts of the compiler use a consistent idea of which
predicates should have typeinfo liveness applied to their bodies when the
relevant option is set. This set is all predicates except the few in
the builtin modules which do not have the required arguments.

compiler/hlds_pred.m:
	Expand the interface of the should_use_typeinfo_liveness family of
	predicates to include an id of the predicate in question, to enable
	them to test whether the pred is a no_type_info_builtin.

compiler/hlds_pred.m:
compiler/polymorphism.m:
	Move the list of no_type_info_builtins from polymorphism to hlds_pred,
	since body_should_use_typeinfo_liveness also needs it now.

compiler/*.m:
	Minor changes to pass the right arguments to predicates of the
	should_use_typeinfo_liveness family, directly or indirectly.
2000-08-08 04:44:54 +00:00
Zoltan Somogyi
a0a6daa06f If we are using typeinfo liveness, then clip the instmap delta fields in
Estimated hours taken: 16

If we are using typeinfo liveness, then clip the instmap delta fields in
goal_infos not to the nonlocals, but to the nonlocals plus the
type info or typeclass info variables needed to describe the types of the
nonlocals (this set is now called the "typeinfo completed nonlocals").

This is necessary for the proper handling of code such as resume_typeinfos.m
in tests/debugger. This involves a call to a procedure with an existentially
typed argument, where the returned argument is processed only in ways that do
not need the typeinfo describing it. The compiler therefore considered the
typeinfo to be local to the call binding it. Its binding was therefore not
recorded in the instmap delta, which in turn meant that in the absence of a
value-giving occurrence, liveness.m considered it not to be born anywhere.
On the other hand, with typeinfo liveness, occurrences of the argument are
also considered value-using occurrences of the typeinfo, so the typeinfo
was considered to die at the last such occurrence. Therefore the typeinfo
died without being born. The current code generator is sloppy enough not
to mind this, but the upcoming eager code generator isn't.

compiler/hlds_goal.m:
	Document the new semantics of instmap_deltas.

compiler/quantification.m:
compiler/mode_util.m:
compiler/modes.m:
compiler/unique_modes.m:
	If typeinfo liveness is set, include the relevant typeinfo variables
	in the set of variables the instmap is limited to.

compiler/modes.m:
	Delete some unused predicates.

compiler/hlds_pred.m:
	Centralize the code for (maybe) completing a set of vars with the set
	of typeinfo vars describing their types here.

compiler/call_gen.m:
compiler/live_vars.m:
	Use the central code in hlds_pred.m.

compiler/accumulator.m:
compiler/cse_detection.m:
compiler/follow_code.m:
compiler/higher_order.m:
compiler/lambda.m:
compiler/liveness.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mode_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
	Call quantification and/or mode_util with the right arguments.
	In some cases, introduce field names, predmode declarations and/or
	shorter type names to make this change easier.
2000-08-03 08:46:44 +00:00
Zoltan Somogyi
9dcab9bee2 Add a new optimization, enabled by the option --unneeded-code.
Estimated hours taken: 40

Add a new optimization, enabled by the option --unneeded-code. This
optimization removes goals whose outputs are not used at all, and moves goals
whose outputs are only used on some computation branches to the starts of
those branches, so they do not need to be executed on other branches.

Such deletions/movements are done only when the semantic switches and the
properties of the relevant goal together permit it.

compiler/unneeded_code.m:
	A new module to perform the goal rearrangement.

compiler/hlds_goal.m:
	The new optimization needs to know how many functors the switched-on
	variable can be bound to, so it can check whether a given number of
	switch arms covers all alternatives or not. To make access to this
	information convenient, we add a field to the goal_path_step
	alternative for switch arm entry that records this number.

compiler/goal_path.m:
	Fill in this number.

	To make this possible, we thread the necessary information through the
	predicates in this module.

compiler/type_util.m:
	Add a utility predicate type_util__switch_type_num_functors, for use
	by the new code in goal_path.m.

compiler/switch_detection.m:
	Avoid duplicated code by using type_util__switch_type_num_functors
	where relevant.

compiler/code_aux.m:
	Add three new auxiliary predicate, code_aux__goal_cannot_loop_or_throw,
	code_aux__goal_can_loop_or_throw and code_aux__goal_can_loop, to the
	existing code_aux__goal_cannot_loop. code_aux__goal_cannot_loop
	now checks only what its name says.

compiler/trace.m:
	Ignore the new field when generating goal paths strings.

compiler/mercury_compile.m:
	Invoke unneeded_code.m if required.

compiler/hlds_pred.m:
	Add some utility predicates for use by unneeded_code.m.

compiler/unused_args.m:
	Use the new utility predicates instead of reimplementing them.

compiler/options.m:
	Define the --unneeded-code option, and its auxiliary,
	--unneeded-code-copy-limit.

doc/user_guide.texi:
	Document the new options.
2000-07-25 09:27:38 +00:00