[m-rev.] diff: more hlc.agc bug fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 5 20:36:46 AEDT 2002


Estimated hours taken: 2
Branches: main

Fix some bugs with the hlc.agc grade where the compiler was generating
references to type_info variables that were not in scope.

compiler/hlds_pred.m:
	Document the invariant that type_info arguments must precede
	non-type_info arguments, since MLDS->C accurate GC relies on this.

compiler/type_util.m:
	Add new function put_typeinfo_vars_first, for use by lamdbda.m
	and ml_code_gen.m.

compiler/lambda.m:
	Call put_typeinfo_vars_first on the arguments of the introduced
	procedures, to ensure that invariant documented in hlds_pred.m holds.

compiler/ml_code_gen.m:
	Call put_typeinfo_vars_first on the list of local variables
	that we generate for each subgoal, to avoid referring to type_info
	variables that are not in scope in the GC tracing code.

Workspace: /home/ceres/fjh/mercury
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.103
diff -u -d -r1.103 hlds_pred.m
--- compiler/hlds_pred.m	22 Feb 2002 01:20:45 -0000	1.103
+++ compiler/hlds_pred.m	5 Mar 2002 06:04:53 -0000
@@ -893,7 +893,12 @@
 
 	% The information specific to a predicate, as opposed to a procedure.
 	% (Functions count as predicates.)
-
+	%
+	% Note that it is an invariant that any type_info-related
+	% variables in the arguments of a predicate must precede any
+	% polymorphically-typed arguments whose type depends on the
+	% values of those type_info-related variables;
+	% accurate GC for the MLDS back-end relies on this.
 :- type pred_info
 	--->	predicate(
 			decl_typevarset	:: tvarset,
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.74
diff -u -d -r1.74 lambda.m
--- compiler/lambda.m	10 Jul 2001 10:45:26 -0000	1.74
+++ compiler/lambda.m	5 Mar 2002 06:40:12 -0000
@@ -456,7 +456,7 @@
 		% name, arity, arg types, determinism,
 		% context, status, etc. for the new predicate.
 
-		ArgVars = ArgVars1,
+		ArgVars = put_typeinfo_vars_first(ArgVars1, VarTypes),
 		list__append(ArgVars, Vars, AllArgVars),
 
 		module_info_name(ModuleInfo0, ModuleName),
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.109
diff -u -d -r1.109 ml_code_gen.m
--- compiler/ml_code_gen.m	18 Feb 2002 07:00:54 -0000	1.109
+++ compiler/ml_code_gen.m	5 Mar 2002 06:21:48 -0000
@@ -1462,16 +1462,21 @@
 	% but which are not local to a subgoal.
 	% (If they're local to a subgoal, they'll be declared
 	% when we generate code for that subgoal.)
+	%
+	% We need to make sure that we declare any type_info or
+	% type_classinfo variables *before* any other variables,
+	% since the GC tracing code for the other variables may
+	% refer to the type_info variables, so they need to be in scope.
 
 	{ Locals = goal_local_vars(Goal) },
 	{ SubGoalLocals = union_of_direct_subgoal_locals(Goal) },
 	{ set__difference(Locals, SubGoalLocals, VarsToDeclareHere) },
-	{ set__to_sorted_list(VarsToDeclareHere, VarsList) },
+	{ set__to_sorted_list(VarsToDeclareHere, VarsList0) },
 	=(MLDSGenInfo),
 	{ ml_gen_info_get_varset(MLDSGenInfo, VarSet) },
 	{ ml_gen_info_get_var_types(MLDSGenInfo, VarTypes) },
-	ml_gen_local_var_decls(VarSet, VarTypes,
-		Context, VarsList, VarDecls),
+	{ VarsList = put_typeinfo_vars_first(VarsList0, VarTypes) },
+	ml_gen_local_var_decls(VarSet, VarTypes, Context, VarsList, VarDecls),
 
 	%
 	% Generate code for the goal in its own code model.
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.104
diff -u -d -r1.104 type_util.m
--- compiler/type_util.m	5 Feb 2002 09:14:45 -0000	1.104
+++ compiler/type_util.m	5 Mar 2002 06:18:57 -0000
@@ -95,13 +95,21 @@
 :- mode type_id_has_hand_defined_rtti(in) is semidet.
 
 	% A test for type_info-related types that are introduced by
-	% polymorphism.m.  Mode inference never infers unique modes
+	% polymorphism.m.  These need to be handled specially in certain
+	% places.  For example, mode inference never infers unique modes
 	% for these types, since it would not be useful, and since we
 	% want to minimize the number of different modes that we infer.
 
 :- pred is_introduced_type_info_type(type).
 :- mode is_introduced_type_info_type(in) is semidet.
 
+	% Given a list of variables, return the permutation
+	% of that list which has all the type_info-related variables
+	% preceding the non-type_info-related variables (with the relative
+	% order of variables within each group being the same as in the
+	% original list).
+:- func put_typeinfo_vars_first(list(prog_var), vartypes) = list(prog_var).
+
 	% In the forwards mode, this predicate checks for a "new " prefix
 	% at the start of the functor name, and removes it if present;
 	% it fails if there is no such prefix.
@@ -522,6 +530,13 @@
 	; Name = "base_typeclass_info"
 	),
 	mercury_private_builtin_module(PrivateBuiltin).
+
+put_typeinfo_vars_first(VarsList, VarTypes) =
+		TypeInfoVarsList ++ NonTypeInfoVarsList :-
+	list__filter((pred(Var::in) is semidet :-
+			Type = map__lookup(VarTypes, Var),
+			is_introduced_type_info_type(Type)),
+		VarsList, TypeInfoVarsList, NonTypeInfoVarsList).
 
 remove_new_prefix(unqualified(Name0), unqualified(Name)) :-
 	string__append("new ", Name, Name0).

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