[m-rev.] for review: fix singleton variable warning problem

Simon Taylor stayl at cs.mu.OZ.AU
Sat Jun 1 01:35:31 AEST 2002


On 31-May-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 31-May-2002, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > 
> > This is still treating the symptom, not the cause. Why do variables
> > in foreign_proc clauses need to be handled differently? Why doesn't
> > this problem occur with Mercury clauses?
> 
> The problem doesn't occur with Mercury clauses because after flattening
> (conversion to SHF), the head variables in Mercury clauses are never
> singletons; the head variables are always "HeadVar__N", which might
> get unified with singleton variables in the body, but which are not
> themselves singletons.
> 
> For foreign_proc clauses, we don't use "HeadVar__N" as the head variables;
> instead, we use the variables that the user specified directly.
>
> One possible solution, then, might be to change the way we handle
> foreign_proc clauses, so that we do introduce "HeadVar__N" variables
> and the corresponding unifications for those.  I don't know if that
> would be a good idea, or if it might result in other problems...

Adding unifications could cause spurious unique mode errors due to
the addition of aliasing that the current mode checker is incapable
of tracking. Howver, it should be possible to specify the HeadVar__N
variables as the arguments of the foreign code goal directly.

The diff below has the same effect as Pete's change, but it also
simplifies the code. This isn't well tested.

Simon.

Index: make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.411
diff -u -u -r1.411 make_hlds.m
--- make_hlds.m	9 May 2002 16:30:55 -0000	1.411
+++ make_hlds.m	31 May 2002 15:22:56 -0000
@@ -5500,7 +5500,7 @@
 clauses_info_add_pragma_foreign_proc(ClausesInfo0, Purity, Attributes0, PredId,
 		ProcId, PVarSet, PVars, OrigArgTypes, PragmaImpl0, Context,
 		PredOrFunc, PredName, Arity, ClausesInfo, ModuleInfo0,
-		ModuleInfo, Info0, Info) -->
+		ModuleInfo, Info, Info) -->
 
 	{ ClausesInfo0 = clauses_info(VarSet0, VarTypes, TVarNameMap,
 		VarTypes1, HeadVars, ClauseList, TI_VarMap, TCI_VarMap,
@@ -5618,7 +5618,6 @@
 	( { MultipleArgs = [_ | _] } ->
 		{ ClausesInfo = ClausesInfo0 },
 		{ ModuleInfo = ModuleInfo1 },
-		{ Info = Info0 },
 		prog_out__write_context(Context),
 		io__write_string(
 			"In `:- pragma foreign_proc' declaration for "),
@@ -5644,12 +5643,7 @@
 		io__write_string("  in the argument list.\n"),
 		io__set_exit_status(1)
 	;
-		% merge the varsets of the proc and the new pragma_c_code
 		{
-		varset__merge_subst(VarSet0, PVarSet, VarSet1, Subst),
-		map__apply_to_list(Args0, Subst, TermArgs),
-		term__term_list_to_var_list(TermArgs, Args),
-
 			% build the pragma_c_code
 		goal_info_init(GoalInfo0),
 		goal_info_set_context(GoalInfo0, Context, GoalInfo1),
@@ -5657,22 +5651,12 @@
 		% this foreign code is inlined
 		add_goal_info_purity_feature(GoalInfo1, Purity, GoalInfo),
 		HldsGoal0 = foreign_proc(Attributes, PredId, 
-			ProcId, Args, ArgInfo, OrigArgTypes, PragmaImpl)
-			- GoalInfo
-		}, 
-			% Apply unifications with the head args.
-			% Since the set of head vars and the set vars in the
-			% pragma foreign code are disjoint, the
-			% unifications can be implemented as
-			% substitutions, and they will be.
-		insert_arg_unifications(HeadVars, TermArgs, Context,
-			head(PredOrFunc, Arity), yes, HldsGoal0, VarSet1,
-			HldsGoal1, VarSet2, transform_info(ModuleInfo1, Info0),
-				transform_info(ModuleInfo, Info)),
-		{
+			ProcId, HeadVars, ArgInfo, OrigArgTypes, PragmaImpl)
+			- GoalInfo,
+		ModuleInfo = ModuleInfo1,
 		map__init(EmptyVarTypes),
 		implicitly_quantify_clause_body(HeadVars,
-			HldsGoal1, VarSet2, EmptyVarTypes,
+			HldsGoal0, VarSet0, EmptyVarTypes,
 			HldsGoal, VarSet, _, _Warnings),
 		NewClause = clause([ProcId], HldsGoal,
 			foreign_language(NewLang), Context),
--------------------------------------------------------------------------
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