[m-dev.] diff: fix quantification bug in lambda.m

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 11 16:03:26 AEST 2000


Estimated hours taken: 0.75

compiler/lambda.m:
	Fix a bug: it wasn't calculating the non-locals correctly.
	This bug caused the MLDS back-end to generate incorrect
	code (which gcc -Wshadow warned about) for compiler/call_gen.m.

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.60
diff -u -d -r1.60 lambda.m
--- compiler/lambda.m	2000/02/08 15:07:53	1.60
+++ compiler/lambda.m	2000/05/11 05:55:50
@@ -82,7 +82,7 @@
 
 :- implementation.
 
-:- import_module hlds_goal, prog_data.
+:- import_module hlds_goal, prog_data, quantification.
 :- import_module hlds_data, globals, options, type_util.
 :- import_module goal_util, prog_util, mode_util, inst_match, llds, arg_info.
 
@@ -105,7 +105,8 @@
 			pred_or_func,
 			string,			% pred/func name
 			aditi_owner,
-			module_info
+			module_info,
+			bool	% true iff we need to recompute the nonlocals
 		).
 
 %-----------------------------------------------------------------------------%
@@ -171,20 +172,34 @@
 	pred_info_get_markers(PredInfo0, Markers),
 	pred_info_get_class_context(PredInfo0, Constraints0),
 	pred_info_get_aditi_owner(PredInfo0, Owner),
+	proc_info_headvars(ProcInfo0, HeadVars),
 	proc_info_varset(ProcInfo0, VarSet0),
 	proc_info_vartypes(ProcInfo0, VarTypes0),
 	proc_info_goal(ProcInfo0, Goal0),
 	proc_info_typeinfo_varmap(ProcInfo0, TVarMap0),
 	proc_info_typeclass_info_varmap(ProcInfo0, TCVarMap0),
+	MustRecomputeNonLocals0 = no,
 
 	% process the goal
 	Info0 = lambda_info(VarSet0, VarTypes0, Constraints0, TypeVarSet0,
 		TVarMap0, TCVarMap0, Markers, PredOrFunc, 
-		PredName, Owner, ModuleInfo0),
-	lambda__process_goal(Goal0, Goal, Info0, Info),
-	Info = lambda_info(VarSet, VarTypes, Constraints, TypeVarSet, 
-		TVarMap, TCVarMap, _, _, _, _, ModuleInfo),
+		PredName, Owner, ModuleInfo0, MustRecomputeNonLocals0),
+	lambda__process_goal(Goal0, Goal1, Info0, Info1),
+	Info1 = lambda_info(VarSet1, VarTypes1, Constraints, TypeVarSet, 
+		TVarMap, TCVarMap, _, _, _, _, ModuleInfo,
+		MustRecomputeNonLocals),
 
+	% check if we need to requantify
+	( MustRecomputeNonLocals = yes ->
+		implicitly_quantify_clause_body(HeadVars,
+			Goal1, VarSet1, VarTypes1, Goal, VarSet, VarTypes,
+			_Warnings)
+	;
+		Goal = Goal1,
+		VarSet = VarSet1,
+		VarTypes = VarTypes1
+	),
+
 	% set the new values of the fields in proc_info and pred_info
 	proc_info_set_goal(ProcInfo0, Goal, ProcInfo1),
 	proc_info_set_varset(ProcInfo1, VarSet, ProcInfo2),
@@ -290,7 +305,7 @@
 		Unification, LambdaInfo0, LambdaInfo) :-
 	LambdaInfo0 = lambda_info(VarSet, VarTypes, _PredConstraints, TVarSet,
 		TVarMap, TCVarMap, Markers, POF, OrigPredName, Owner,
-		ModuleInfo0),
+		ModuleInfo0, MustRecomputeNonLocals0),
 
 		% Calculate the constraints which apply to this lambda
 		% expression. 
@@ -327,8 +342,18 @@
 
 	% We need all the typeinfos, including the ones that are not used,
 	% for the layout structure describing the closure.
-	set__union(NonLocals1, ExtraTypeInfos, NonLocals),
+	NewTypeInfos = ExtraTypeInfos `set__difference` NonLocals1,
+	NonLocals = NonLocals1 `set__union` NewTypeInfos,
 
+	% If we added variables to the nonlocals of the lambda goal,
+	% then we need to recompute the nonlocals for the procedure
+	% that contains it.
+	( \+ set__empty(NewTypeInfos) ->
+		MustRecomputeNonLocals = yes
+	;
+		MustRecomputeNonLocals = MustRecomputeNonLocals0
+	),
+
 	set__to_sorted_list(NonLocals, ArgVars1),
 
 	( 
@@ -530,7 +555,7 @@
 		VarToReuse, cell_is_unique, RLExprnId),
 	LambdaInfo = lambda_info(VarSet, VarTypes, Constraints, TVarSet,
 		TVarMap, TCVarMap, Markers, POF, OrigPredName, Owner,
-		ModuleInfo).
+		ModuleInfo, MustRecomputeNonLocals).
 
 :- pred lambda__constraint_contains_vars(list(tvar), class_constraint).
 :- mode lambda__constraint_contains_vars(in, in) is semidet.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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