[m-rev.] for review: generalize the specialization of compare/3 predicates

Simon Taylor stayl at cs.mu.OZ.AU
Tue Feb 5 01:30:25 AEDT 2002


On 21-Jan-2002, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> compiler/unify_proc.m:
> 	Generalize the code that generates comparison procedures that
> 	explicitly compare each function symbol with every other, to
> 	handle types with any number of function symbols. Rename some
> 	predicates to make clearer the distinction between these predicates,
> 	which generate comparison predicates whose size is quadratic in the
> 	the number of function symbols in the type, from the predicates
> 	which generate comparison predicates whose size is linear in the
> 	the number of function symbols in the type.

Just some minor nits.

> Index: compiler/unify_proc.m
> ===================================================================
> @@ -1069,52 +1063,32 @@
>  				Ctor, Res, H1, H2,
>  				Context, Clauses)
>  		;
> -			unify_proc__generate_du_general_compare_clauses(Type,
> +			unify_proc__generate_du_linear_compare_clauses(Type,
>  				Ctors, Res, H1, H2, Context, Clauses)
>
>  	;
> -		{ Ctors = [Ctor1, Ctor2] },
> +		{ Ctors = [_, _ | _] },

Can't you remove the special case handling of the single
constructor case as well?

>  		{ globals__lookup_int_option(Globals, compare_specialization,
>  			CompareSpec) },
> -		( { CompareSpec >= 2 } ->
> -			unify_proc__generate_du_two_compare_clauses(
> -				Ctor1, Ctor2, Res, H1, H2,
> -				Context, Clauses)
> -		;
> -			unify_proc__generate_du_general_compare_clauses(Type,
> +		{ list__length(Ctors, NumCtors) },
> +		( { CompareSpec >= NumCtors } ->
> +			unify_proc__generate_du_quad_compare_clauses(
>  				Ctors, Res, H1, H2, Context, Clauses)

The comparison would be slightly easier to read with the constant
(CompareSpec) on the right. I'd also suggest not abbreviating "quadratic".

> -	{ goal_info_init(GoalInfo0) },
> -	{ goal_info_set_context(GoalInfo0, Context, GoalInfo) },
> -	{ map__init(Empty) },
> -	{ Goal = disj([Case11, Case12, Case13, Case21, Case22, Case23,
> -		Case31, Case32, Case33], Empty) - GoalInfo },
> -	{ HeadVars = [R, X, Y] },
> -	unify_proc__quantify_clauses_body(HeadVars, Goal, Context, Clauses).
> +:- pred unify_proc__generate_du_quad_compare_clauses_2(
> +	constructor::in, list(constructor)::in, string::in,
> +	prog_var::in, prog_var::in, prog_var::in, prog_context::in,
> +	list(hlds_goal)::in, list(hlds_goal)::out,
> +	unify_proc_info::in, unify_proc_info::out) is det.
>  
> +unify_proc__generate_du_quad_compare_clauses_2(_LeftCtor,
> +		[], _Cmp, _R, _X, _Y, _Context, Cases, Cases) --> [].
> +unify_proc__generate_du_quad_compare_clauses_2(LeftCtor,
> +		[RightCtor | RightCtors], Cmp0, R, X, Y, Context,
> +		Cases0, Cases) -->
> +	( { LeftCtor = RightCtor } ->
> +		unify_proc__generate_compare_case(LeftCtor, R, X, Y, Context,
> +			Case),
> +		{ Cmp1 = "<" }
> +	;
> +		unify_proc__generate_asymmetric_compare_case(LeftCtor,
> +			RightCtor, Cmp0, R, X, Y, Context, Case),
> +		{ Cmp1 = Cmp0 }
> +	),
> +	unify_proc__generate_du_quad_compare_clauses_2(LeftCtor, RightCtors,
> +		Cmp1, R, X, Y, Context, [Case | Cases0], Cases).

It might be slightly better to reverse the list of cases so
they are in sorted order.

Simon.
--------------------------------------------------------------------------
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