[m-dev.] New HLDS scoping proposal

Ralph Becket rafe at cs.mu.OZ.AU
Tue Aug 31 17:31:06 AEST 2004


This proposal aims at
(a) solving easily now a couple of problems (that should be solved
properly at some point) concerning flattening to HLDS, type analysis and
mode analysis and
(b) provide a fairly general scoping mechanism in the HLDS which will
support such things as existential quantification of variables, promises
of various kinds, and so forth.

[The specific problem with (a) is that, roughly speaking, flattening
will turn
	X = f(P, Q, R)
into
	X = f(V0, V1, V2),
	V0 = P,
	V1 = Q,
	V2 = R
which is good for type analysis, but bad for mode analysis.  Reversing
the order reverses the situation.]

The proposal is essentially this: we remove the some/3 constructor from
the hlds_goal_expr type and replace it with a scope/2 constructor:

	scope(
		scope_kind	:: scope_kind,
		scope_goal	:: hlds_goal
	)

where scope_kind might be something like

:- type scope_kind
	--->	{ some(
			some_exist_vars	:: list(prog_var),
			some_can_remove :: can_remove
		) }
	;	flattened_goal(flattened_direction)
	...

:- type flattened_direction
	--->	head_then_args		% Good for type analysis.
	;	args_then_head		% Good for mode analysis.

The some/2 constructor replaces the existing some/3 constructor.

The flattened_goal/1 constructor is introduced during flattening to HLDS
and indicates that if the scope_goal is a conjunction then (a) it has
been flattened in the given direction and (b) it is safe to reverse the
conjunction to optimise analysis.  Other than that this scope_kind
carries no significance.

The ... in the definition of scope_kind might one day include things
like

	;	promise_pure
	;	promise_semipure
	;	promise_only_solution

if we choose to add such things to the language.

After talking to Zoltan, we anticipate making this change would take
about three days of boiler plating, which would be quite a bit less than
that required to do any serious surgery on the type or mode analysis
components.

Comments welcome.

-- Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list