[m-rev.] diff/for review: fix hlc.agc grade

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Jan 28 16:03:50 AEDT 2005


(Pending bootcheck and running the tests in hlc.agc)
XXX This is a bit hacky but that's mainly because the code
that causes the problem is also a bit of a hack.

Estimated hours taken: 7
Branches: main

Workaround a problem in the hlc.agc grade that were caused by
the recent changes to ml_code_util.m.

compiler/ml_code_util.m:
	Start the func_label counter in the ml_gen_info structure
	at 1 rather than 0 in order to avoid off-by-one errors
	in the code that performs the shadow stack transformation
	for accurate gc.  The problem eventually manifests itself
	in the generated code as two separate C functions that
	have the same name.

	Add an XXX comment about the above.

	Put the variables that in initialise the ml_gen_info structure
	in the ml_gen_info_init function in the correct order.  The
	compiler did not pick this up because all of the ones that
	were out of order have the same type.

compiler/ml_elim_nested.m:
	Reorder some code so that it follows the natural data flow and
	readers don't have to mentally perform mode analysis to work
	out what is going on.


Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.89
diff -u -r1.89 ml_code_util.m
--- compiler/ml_code_util.m	24 Jan 2005 02:50:17 -0000	1.89
+++ compiler/ml_code_util.m	28 Jan 2005 04:49:24 -0000
@@ -2546,10 +2546,10 @@
 			% for calls to private_builtin__gc_trace)
 			%

-			module_info	:: module_info,
+			module_info	:: module_info,
 			pred_id		:: pred_id,
 			proc_id		:: proc_id,
-			varset		:: prog_varset,
+			varset		:: prog_varset,
 			var_types	:: map(prog_var, prog_type),
 			byref_output_vars :: list(prog_var),
 					% output arguments that are passed by
@@ -2565,7 +2565,7 @@

 			func_label	:: counter,
 			commit_label	:: counter,
-			label		:: counter,
+			label		:: counter,
 			cond_var	:: counter,
 			conv_var	:: counter,
 			const_num	:: counter,
@@ -2593,9 +2593,16 @@
 		VarTypes),
 	ValueOutputVars = [],

-	counter__init(0, LabelCounter),
-	counter__init(0, FuncLabelCounter),
+	% XXX This needs to start at 1 rather than 0 otherwise the
+	% transformation for adding the shadow stack for accurate garbage
+	% collection does not work properly and we will end up generating
+	% two C functions with the same name.
+	%
+	% ( See ml_elim_nested.gen_gc_trace_func/8 for details).
+	%
+ 	counter__init(1, FuncLabelCounter),
 	counter__init(0, CommitLabelCounter),
+	counter__init(0, LabelCounter),
 	counter__init(0, CondVarCounter),
 	counter__init(0, ConvVarCounter),
 	counter__init(0, ConstCounter),
@@ -2606,15 +2613,15 @@

 	Info = ml_gen_info(
 			ModuleInfo,
-			PredId,
-			ProcId,
-			VarSet,
+			PredId,
+			ProcId,
+			VarSet,
 			VarTypes,
 			ByRefOutputVars,
 			ValueOutputVars,
-			LabelCounter,
 			FuncLabelCounter,
 			CommitLabelCounter,
+			LabelCounter,
 			CondVarCounter,
 			ConvVarCounter,
 			ConstCounter,
@@ -2658,7 +2665,7 @@
 ml_gen_info_new_label(Label, Info0, Info) :-
 	Counter0 = Info0 ^ label,
 	counter__allocate(Label, Counter0, Counter),
-	Info = Info0 ^ label := Counter.
+	Info = Info0 ^ label := Counter.

 ml_gen_info_new_func_label(Label, Info0, Info) :-
 	Counter0 = Info0 ^ func_label,
Index: compiler/ml_elim_nested.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.67
diff -u -r1.67 ml_elim_nested.m
--- compiler/ml_elim_nested.m	19 Jan 2005 03:10:43 -0000	1.67
+++ compiler/ml_elim_nested.m	28 Jan 2005 04:53:22 -0000
@@ -475,7 +475,6 @@
 ml_elim_nested(Action, MLDS0, MLDS, !IO) :-
 	globals__io_get_globals(Globals, !IO),
 	MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0),
-	MLDS = mlds(ModuleName, ForeignCode, Imports, Defns),
 	MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
 	OuterVars = [],
 	DefnsList = list__map(
@@ -488,7 +487,8 @@
 	% When we hoist them out, that leads to duplicate definitions here.
 	% So we need to check for and eliminate any duplicate definitions
 	% of constants.
-	Defns = list__remove_dups(Defns1).
+	Defns = list__remove_dups(Defns1),
+	MLDS = mlds(ModuleName, ForeignCode, Imports, Defns).

 	% Either eliminated nested functions:
 	% Hoist out any nested function occurring in a single mlds__defn.

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