[m-rev.] for review: trace goals

Zoltan Somogyi zs at csse.unimelb.edu.au
Thu Jul 27 11:14:09 AEST 2006

This is a mostly complete diff that I would like to commit as soon as possible,
since it will get conflicts with most other changes. The missing things are
(a) documentation, and (b) removing any traces of the previous existence
of trace goals if they are disabled at compile time. I will work on those
during the rest of the week.

The diff is too big to post; it is in ~zs/tmp/DIFF.trace.


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

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.

	Add "trace" as an operator.

	Define data types to represent the various attributes of trace goals.

	Rename some function symbols to avoid ambiguities.

	Extend the parse tree representation of goals with a trace goal.

	Output the new kind of goal and its components.

	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.

	Output the new construct in the HLDS.

	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.

	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

	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.

	Find and accumulate syntax errors as terms are being parsed.

	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

	Use error_util for some error messages.

	Add the predicates referred to by the transformation in add_clause.m.

	Rename a predicate to avoid ambiguity.

	Do not print error messages about missing clauses if some errors have
	been detected previously.

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

	Add trace goals as a reason for locking variables.

	Rename some function symbols to avoid ambiguity.

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

	Insist on the code in trace goal scopes being det or cc_multi.

	Generate the error message if the code in a trace goal scope isn't det
	or cc_multi.

	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.

	Tell simplify when it is being invoked at the end of the front end.

	Rename a predicate to avoid ambiguity.

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

	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.

	Document this name change.

	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.

	Rename the function symbols of the grade_component type,
	since "trace" is now an operator.

	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.

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

	Tell commit_gen.m what kind of scope it is generating code for.

	Generate code for runtime conditions when handling the foreign_procs
	created by simplify.m.

	Allow pragma_c_gen.m to record what environment variables it has
	generated references to.

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

	Handle the new LLDS construct, and tell mkinit which environment
	variables need C globals created for them.

	Rename some predicates to avoid ambiguity.

	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.

	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.

	Add some predicates that are useful in prog_io*.m.

	Minor cleanup.

	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at compile time.

	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at run time.

	Enable the new test cases.

	Update the expected output for the new versions of the error messages
	now being generated.
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au

More information about the reviews mailing list