[m-rev.] for review: warnings in duplicated code

Julien Fischer juliensf at cs.mu.OZ.AU
Thu May 25 17:38:54 AEST 2006

On Thu, 25 May 2006, Zoltan Somogyi wrote:

> For unifications of the form X = f, we usually emit warnings if we know
> from previous unifications that X cannot be bound to f. There was already
> one exception to this: if some of the procedure's arguments had initial insts
> such as in(g), because in such cases the failure of the unification could be
> caused by this initial mode, and the exact same unification could succeed
> in another mode in which the initial inst of that variable is in(f).
> This diff adds another exception: when the unification is in code that was
> duplicated by switch detection. Consider this code:
> 	% switch on X
> 	(
> 		X = e,
> 		...
> 	;
> 		( X = f
> 		; X = g
> 		; X = h
> 		),
> 		...
> 		( X = f ->
> 			...
> 		;
> 			...
> 		)
> 	)
> The idea is that cases of f, g and h are handled mostly the same way, but that
> f needs a bit of special handling. This used to give a warning, because the
> switch detection creates three copies of the if-then-else: one each inside
> the switch arms for f, g and h. In the arm for f, the condition cannot fail,
> and in the arms for g and h, the condition cannot succeed, yet giving warnings
> about the condition not being able to fail or succeed would be misleading.
> compiler/hlds_goal.m:
> 	Add a goal feature to denote that the goal is duplicated by switch
> 	detection.
> compiler/saved_vars.m:
> 	Conform to the new feature.
> compiler/switch_detection.m:
> 	Attach this feature to goals as they are being duplicated.
> compiler/mode_info.m:
> 	Add a field to the mode_info that says whether we are inside such
> 	goals.
> compiler/modes.m:
> compiler/unique_modes.m:
> 	Set this field appropriately.
> compiler/modecheck_unify.m:
> 	When finding a unification of the form X = f where the inst of X
> 	says that it cannot be bound to X, only generate a warning if we are
> 	not inside a duplicated goal.
> compiler/simplify.m:
> 	Add a field to the simplify_ that says whether we are inside
> 	a duplicated goal, keep it up to date, and don't generate warnings
> 	about too-simple if-then-elses if the field say they could be due to
> 	the code duplication.
> tests/hard_coded/switch_detect.m:
> 	Extend this existing test case to test the new behavior.
> tests/hard_coded/Mercury.options:
> 	Force the compilation of switch_detect.m to fail if there are any
> 	warnings.

That looks fine.  (You'll need to commit this on the release branch
as well.)

mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe

More information about the reviews mailing list