[m-dev.] for review: minor polymorphism cleanup

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Jul 19 11:48:03 AEST 2000


For review by DJ.

compiler/polymorphism.m:
	Simplify the code of maybe_init_second_cell by not testing conditions
	twice.

Zoltan.

Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.188
diff -u -b -r1.188 polymorphism.m
--- compiler/polymorphism.m	2000/05/25 02:35:03	1.188
+++ compiler/polymorphism.m	2000/07/18 05:54:18
@@ -156,7 +156,6 @@
 %
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
 %
 % Transformation of code using existentially quantified types:
 % 
@@ -2447,10 +2446,29 @@
 polymorphism__maybe_init_second_cell(ArgTypeInfoVars, ArgTypeInfoGoals, Type,
 		IsHigherOrder, BaseVar, VarSet0, VarTypes0, ExtraGoals0,
 		Var, VarSet, VarTypes, ExtraGoals) :-
-	( 
-		ArgTypeInfoVars = [],
-		IsHigherOrder = no
-	->
+	% Unfortunately, if we have higher order terms, we
+	% can no longer just optimise them to be the actual
+	% type_ctor_info
+	( IsHigherOrder = yes ->
+		list__length(ArgTypeInfoVars, PredArity),
+		polymorphism__make_count_var(PredArity,
+			VarSet0, VarTypes0, ArityVar, ArityGoal,
+			VarSet1, VarTypes1),
+		polymorphism__init_type_info_var(Type,
+			[BaseVar, ArityVar | ArgTypeInfoVars], "type_info",
+			VarSet1, VarTypes1, Var, TypeInfoGoal,
+			VarSet, VarTypes),
+		list__append([ArityGoal |  ArgTypeInfoGoals], [TypeInfoGoal],
+			ExtraGoals1),
+		list__append(ExtraGoals0, ExtraGoals1, ExtraGoals)
+	; ArgTypeInfoVars = [_ | _] ->
+		polymorphism__init_type_info_var(Type,
+			[BaseVar | ArgTypeInfoVars], "type_info",
+			VarSet0, VarTypes0, Var, TypeInfoGoal,
+			VarSet, VarTypes),
+		list__append(ArgTypeInfoGoals, [TypeInfoGoal], ExtraGoals1),
+		list__append(ExtraGoals0, ExtraGoals1, ExtraGoals)
+	;
 		Var = BaseVar,
 
 		% Since this type_ctor_info is pretending to be
@@ -2462,31 +2480,6 @@
 
 		VarSet = VarSet0,
 		ExtraGoals = ExtraGoals0
-	;
-		% Unfortunately, if we have higher order terms, we
-		% can no longer just optimise them to be the actual
-		% type_ctor_info
-		(
-			IsHigherOrder = yes
-		->
-			list__length(ArgTypeInfoVars, PredArity),
-			polymorphism__make_count_var(PredArity, VarSet0,
-				VarTypes0, ArityVar, ArityGoal, VarSet1,
-				VarTypes1),
-			TypeInfoArgVars = [BaseVar, ArityVar | ArgTypeInfoVars],
-			TypeInfoArgGoals = [ArityGoal |  ArgTypeInfoGoals]
-		;
-			TypeInfoArgVars = [BaseVar | ArgTypeInfoVars],
-			TypeInfoArgGoals = ArgTypeInfoGoals,
-			VarTypes1 = VarTypes0,
-			VarSet1 = VarSet0
-		),
-		polymorphism__init_type_info_var(Type,
-			TypeInfoArgVars, "type_info",
-			VarSet1, VarTypes1, Var, TypeInfoGoal,
-			VarSet, VarTypes),
-		list__append(TypeInfoArgGoals, [TypeInfoGoal], ExtraGoals1),
-		list__append(ExtraGoals0, ExtraGoals1, ExtraGoals)
 	).
 
 	% Create a unification `CountVar = <NumTypeArgs>'
--------------------------------------------------------------------------
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