diff: polymorphism.m bug fix

Fergus Henderson fjh at cs.mu.oz.au
Sat Aug 9 14:34:36 AEST 1997


Hi,

Tom, could you please review this one?

compiler/polymorphism.m:
	Fix another bug in the recalculation of the non-local variables:
	we need to requantify if we have added any type variables,
	not just if we have added type variables that are non-local
	at the top level.

Index: polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.114
diff -u -r1.114 polymorphism.m
--- polymorphism.m	1997/08/05 04:37:35	1.114
+++ polymorphism.m	1997/08/09 04:28:37
@@ -659,31 +659,31 @@
 polymorphism__fixup_quantification(Goal0, Goal, Info0, Info) :-
 	Info0 = poly_info(VarSet0, VarTypes0, TypeVarSet, TypeVarMap,
 			ModuleInfo),
-	%
-	% A type-info variable may be non-local to a goal if any of
-	% the ordinary non-local variables for that goal are polymorphically
-	% typed with a type that depends on that type-info variable.
-	%
-	Goal0 = _ - GoalInfo0,
-	goal_info_get_nonlocals(GoalInfo0, NonLocals),
-	set__to_sorted_list(NonLocals, NonLocalsList),
-	map__apply_to_list(NonLocalsList, VarTypes0, NonLocalsTypes),
-	term__vars_list(NonLocalsTypes, NonLocalTypeVars),
-	solutions(lambda([TypeInfoVar::out] is nondet, (
-			list__member(Var, NonLocalTypeVars),
-			map__search(TypeVarMap, Var, TypeInfoVar)
-		)), ExtraNonLocals),
-	( ExtraNonLocals = [] ->
-		Goal = Goal0,
-		VarTypes = VarTypes0,
-		VarSet = VarSet0
+	( map__is_empty(TypeVarMap) ->
+		Info = Info0,
+		Goal = Goal0
 	;
-		set__sorted_list_to_set(ExtraNonLocals, NewOutsideVars),
+		%
+		% A type-info variable may be non-local to a goal if any of
+		% the ordinary non-local variables for that goal are
+		% polymorphically typed with a type that depends on that
+		% type-info variable.
+		%
+		Goal0 = _ - GoalInfo0,
+		goal_info_get_nonlocals(GoalInfo0, NonLocals),
+		set__to_sorted_list(NonLocals, NonLocalsList),
+		map__apply_to_list(NonLocalsList, VarTypes0, NonLocalsTypes),
+		term__vars_list(NonLocalsTypes, NonLocalTypeVars),
+		solutions_set(lambda([TypeInfoVar::out] is nondet, (
+				list__member(Var, NonLocalTypeVars),
+				map__search(TypeVarMap, Var, TypeInfoVar)
+			)), NewOutsideVars),
 		set__union(NewOutsideVars, NonLocals, OutsideVars),
 		implicitly_quantify_goal(Goal0, VarSet0, VarTypes0,
-			OutsideVars, Goal, VarSet, VarTypes, _Warnings)
-	),
-	Info = poly_info(VarSet, VarTypes, TypeVarSet, TypeVarMap, ModuleInfo).
+			OutsideVars, Goal, VarSet, VarTypes, _Warnings),
+		Info = poly_info(VarSet, VarTypes, TypeVarSet, TypeVarMap,
+				ModuleInfo)
+	).
 
 :- pred polymorphism__process_lambda(pred_or_func, list(var), list(mode),
 		determinism, set(var), hlds_goal, unification,

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



More information about the developers mailing list