[m-dev.] diff: fix bug in Aditi aggregates

Simon TAYLOR stayl at cs.mu.OZ.AU
Mon May 8 16:21:22 AEST 2000


Estimated hours taken: 0.5

compiler/magic_util.m:
	Fix a bug in the handling of aggregates over base relations
	which caused a failure at runtime.


Index: magic_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/magic_util.m,v
retrieving revision 1.8
diff -u -u -r1.8 magic_util.m
--- magic_util.m	2000/05/05 03:49:41	1.8
+++ magic_util.m	2000/05/08 04:58:01
@@ -439,7 +439,8 @@
 	(
 		{ Closure = unify(_, _, UniMode, Uni0, Context) - Info },
 		{ Uni0 = construct(Var, ConsId0, _, Modes, _, _, _) },
-		{ ConsId0 = pred_const(PredId0, ProcId0, Method) },
+		{ ConsId0 = pred_const(PredId0, ProcId0, Method) }
+	->
 		%
 		% Replace the pred_proc_id of the procedure being aggregated
 		% over with its Aditi version.
@@ -452,22 +453,32 @@
 			ProcId = ProcId0,
 			ConsId = ConsId0
 		},
-		{ hlds_pred__is_derived_relation(ModuleInfo0, PredId) }
-	->
 
-		%
-		% Create the input relation for the aggregate query.
-		% This is just `true', since we don't allow curried
-		% arguments (except for aditi:states).
-		%
-		magic_info_get_magic_proc_info(MagicProcInfo),
-		{ map__lookup(MagicProcInfo, proc(PredId, ProcId),
-			CallProcInfo) },
-		{ CallProcInfo = magic_proc_info(_, MagicInputs, _, _, _) },
-
-		{ true_goal(InputGoal) },
-		magic_util__create_input_closures(MagicInputs, [], [],
-			InputGoal, CallProcInfo, 1, InputGoals, InputVars),
+		( { hlds_pred__is_derived_relation(ModuleInfo0, PredId) } ->
+
+			%
+			% Create the input relation for the aggregate query.
+			% This is just `true', since we don't allow curried
+			% arguments (except for aditi:states).
+			%
+			magic_info_get_magic_proc_info(MagicProcInfo),
+			{ map__lookup(MagicProcInfo, proc(PredId, ProcId),
+				CallProcInfo) },
+			{ CallProcInfo = magic_proc_info(_, MagicInputs,
+						_, _, _) },
+
+			{ true_goal(InputGoal) },
+			magic_util__create_input_closures(MagicInputs, [], [],
+				InputGoal, CallProcInfo, 1,
+				InputGoals, InputVars)
+		;
+			% Base relation. It could actually be another
+			% aggregate, but if aggregate becomes a new goal
+			% type we won't be able to handle that, in the
+			% same way that call(call(X)) doesn't work. 
+			{ InputGoals = [] },
+			{ InputVars = [] }
+		),
 
 		% Update the unify_rhs.
 		magic_info_get_module_info(ModuleInfo),
@@ -475,8 +486,8 @@
 		{ pred_info_module(CallPredInfo, PredModule) },
 		{ pred_info_name(CallPredInfo, PredName) },
 		{ list__length(InputVars, Arity) },
-		{ Rhs = functor(cons(qualified(PredModule, PredName), Arity),
-				InputVars) },
+		{ Rhs = functor(cons(qualified(PredModule, PredName),
+				Arity), InputVars) },
 
 		{ VarToReuse = no },
 		{ RLExprnId = no },
@@ -486,10 +497,8 @@
 
 		{ list__append(InputGoals, [Goal1], InputAndClosure) }
 	;
-		% Base relation. It could actually be another aggregate,
-		% but if aggregate becomes a new goal type we won't be able to
-		% handle that, in the same way that call(call(X)) doesn't work. 
-		{ InputAndClosure = [Closure] }
+		{ error(
+	"magic_util__setup_aggregate_input: non-closure input to aggregate") }
 	).
 
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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