[m-rev.] hlc.agc: fix GC of closure wrappers

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jun 5 00:43:53 AEST 2002


On 02-Jun-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Implement the last remaining bits needed to do accurate GC for
> closure wrappers.
>
> compiler/ml_call_gen.m:
> 	Add an extra boolean argument to ml_gen_call and
> 	ml_gen_box_or_unbox_lval specifying whether or not
> 	the calling procedure is a closure wrapper.
> 	If it is, declare any local variables allocated
> 	to hold temporaries needed for boxing/unboxing
> 	using ml_gen_local_for_output_arg from ml_closure_gen.m,
> 	so that the GC tracing code gets handled right.
> 
> compiler/ml_closure_gen.m:
> 	Pass `yes' for the new boolean argument to ml_gen_call.
> 	Export ml_gen_local_for_output_arg, for use by ml_call_gen.m.
> 	Fix a bug where the `allocated_memory_cells' list was not being
> 	initialized.
> 
> compiler/ml_code_gen.m:
> 	Pass `no' for the new boolean argument to ml_gen_call
> 	and ml_gen_box_or_unbox_lval.

I was finally able to test this successfully.  Getting it to work
required some additional changes, hence the following relative diff.
I will go ahead and commit this now.

--- CHANGES11	Sun Jun  2 21:08:42 2002
+++ CHANGES11.new	Wed Jun  5 00:40:58 2002
@@ -13,12 +13,16 @@
 	to hold temporaries needed for boxing/unboxing
 	using ml_gen_local_for_output_arg from ml_closure_gen.m,
 	so that the GC tracing code gets handled right.
+	Also add an extra int argument to ml_gen_box_or_unbox_lval,
+	specifying the argument number, since this is needed by
+	ml_gen_local_for_output_arg.
 
 compiler/ml_closure_gen.m:
 	Pass `yes' for the new boolean argument to ml_gen_call.
 	Fix a bug where the `allocated_memory_cells' list was not being
 	initialized.
 	Export ml_gen_local_for_output_arg, for use by ml_call_gen.m.
+	Fix an off-by-one bug in ml_gen_local_for_output_arg.
 
 compiler/ml_code_gen.m:
 	Pass `no' for the new boolean argument to ml_gen_call

diff -u compiler/ml_call_gen.m compiler/ml_call_gen.m
--- compiler/ml_call_gen.m
+++ compiler/ml_call_gen.m
@@ -73,7 +73,7 @@
 :- mode ml_gen_box_or_unbox_rval(in, in, in, out, in, out) is det.
 
 	% ml_gen_box_or_unbox_lval(CallerType, CalleeType, VarLval, VarName,
-	%	Context, ForClosureWrapper,
+	%	Context, ForClosureWrapper, ArgNum,
 	%	ArgLval, ConvDecls, ConvInputStatements, ConvOutputStatements):
 	%
 	% This is like `ml_gen_box_or_unbox_rval', except that it
@@ -90,12 +90,14 @@
 	% If ForClosureWrapper = yes, then the type_info for type variables
 	% in CallerType may not be available in the current procedure, so
 	% the GC tracing code for the ConvDecls (if any) should obtain the
-	% type_info from the corresponding entry in the `type_params' local.
+	% type_info from the ArgNum-th entry in the `type_params' local.
+	% (If ForClosureWrapper = no, then ArgNum is unused.)
 	%
 :- pred ml_gen_box_or_unbox_lval(prog_type, prog_type, mlds__lval, var_name,
-		prog_context, bool, mlds__lval, mlds__defns, mlds__statements,
-		mlds__statements, ml_gen_info, ml_gen_info).
-:- mode ml_gen_box_or_unbox_lval(in, in, in, in, in, in, out, out, out, out,
+		prog_context, bool, int, mlds__lval,
+		mlds__defns, mlds__statements, mlds__statements,
+		ml_gen_info, ml_gen_info).
+:- mode ml_gen_box_or_unbox_lval(in, in, in, in, in, in, in, out, out, out, out,
 		in, out) is det.
 
         % Generate the appropriate MLDS type for a continuation function
@@ -246,7 +248,7 @@
 	ml_gen_var_list(ArgVars, ArgLvals),
 	ml_variable_types(ArgVars, ActualArgTypes),
 	ml_gen_arg_list(ArgNames, ArgLvals, ActualArgTypes, BoxedArgTypes,
-		ArgModes, PredOrFunc, CodeModel, Context, no,
+		ArgModes, PredOrFunc, CodeModel, Context, no, 1,
 		InputRvals, OutputLvals, OutputTypes,
 		ConvArgDecls, ConvOutputStatements),
 	{ ClosureRval = unop(unbox(ClosureArgType), lval(ClosureLval)) },
@@ -359,7 +361,7 @@
 	% to pass as the function call's arguments and return values
 	%
 	ml_gen_arg_list(ArgNames, ArgLvals, ActualArgTypes, PredArgTypes,
-		ArgModes, PredOrFunc, CodeModel, Context, ForClosureWrapper,
+		ArgModes, PredOrFunc, CodeModel, Context, ForClosureWrapper, 1,
 		InputRvals, OutputLvals, OutputTypes,
 		ConvArgDecls, ConvOutputStatements),
 
@@ -614,14 +616,14 @@
 %
 :- pred ml_gen_arg_list(list(var_name), list(mlds__lval), list(prog_type),
 		list(prog_type), list(mode), pred_or_func, code_model,
-		prog_context, bool, list(mlds__rval), list(mlds__lval),
+		prog_context, bool, int, list(mlds__rval), list(mlds__lval),
 		list(mlds__type), mlds__defns, mlds__statements,
 		ml_gen_info, ml_gen_info).
-:- mode ml_gen_arg_list(in, in, in, in, in, in, in, in, in,
+:- mode ml_gen_arg_list(in, in, in, in, in, in, in, in, in, in,
 		out, out, out, out, out, in, out) is det.
 
 ml_gen_arg_list(VarNames, VarLvals, CallerTypes, CalleeTypes, Modes,
-		PredOrFunc, CodeModel, Context, ForClosureWrapper,
+		PredOrFunc, CodeModel, Context, ForClosureWrapper, ArgNum,
 		InputRvals, OutputLvals, OutputTypes,
 		ConvDecls, ConvOutputStatements) -->
 	(
@@ -646,7 +648,7 @@
 		ml_gen_arg_list(VarNames1, VarLvals1,
 			CallerTypes1, CalleeTypes1, Modes1,
 			PredOrFunc, CodeModel, Context, ForClosureWrapper,
-			InputRvals1, OutputLvals1, OutputTypes1,
+			ArgNum + 1, InputRvals1, OutputLvals1, OutputTypes1,
 			ConvDecls1, ConvOutputStatements1),
 		=(MLDSGenInfo),
 		{ ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
@@ -690,8 +692,8 @@
 			%
 			ml_gen_box_or_unbox_lval(CallerType, CalleeType,
 				VarLval, VarName, Context, ForClosureWrapper,
-				ArgLval, ThisArgConvDecls, _ThisArgConvInput,
-				ThisArgConvOutput),
+				ArgNum, ArgLval, ThisArgConvDecls,
+				_ThisArgConvInput, ThisArgConvOutput),
 			{ ConvDecls = ThisArgConvDecls ++ ConvDecls1 },
 			{ ConvOutputStatements =
 				(if ArgMode = top_out then
@@ -841,7 +843,7 @@
 	).
 	
 ml_gen_box_or_unbox_lval(CallerType, CalleeType, VarLval, VarName, Context,
-		ForClosureWrapper, ArgLval, ConvDecls,
+		ForClosureWrapper, ArgNum, ArgLval, ConvDecls,
 		ConvInputStatements, ConvOutputStatements) -->
 	%
 	% First see if we can just convert the lval as an rval;
@@ -887,10 +889,7 @@
 			% For closure wrappers, the argument type_infos are
 			% stored in the `type_params' local, so we need to
 			% handle the GC tracing code specially
-			( { type_util__var(CallerType, TypeVar) } ->
-				% XXX here we rely on the allocation order
-				%     of type variable numbers
-				{ term__var_to_int(TypeVar, ArgNum) },
+			( { type_util__var(CallerType, _TypeVar) } ->
 				ml_gen_local_for_output_arg(ArgVarName,
 					CalleeType, ArgNum, Context,
 					ArgVarDecl)
diff -u compiler/ml_closure_gen.m compiler/ml_closure_gen.m
--- compiler/ml_closure_gen.m
+++ compiler/ml_closure_gen.m
@@ -601,7 +601,7 @@
 	%	MR_MemoryList allocated_memory_cells = NULL;
     	%	type_info = MR_make_type_info_maybe_existq(type_params,
 	%	    ((MR_Closure*)closure)->MR_closure_layout
-	%	    	->MR_closure_arg_pseudo_type_info[ <arg number> ],
+	%	    	->MR_closure_arg_pseudo_type_info[<arg number> - 1],
 	%           NULL, NULL, &allocated_memory_cells);
 	%	mercury__private_builtin__gc_trace_1_0(type_info, &conv_retval);
 	%       MR_deallocate(allocated_memory_cells);
@@ -1071,7 +1071,7 @@
 	%	MR_TypeInfo type_info;
 	%	MR_MemoryList allocated_memory_cells = NULL;
     	%	type_info = MR_make_type_info_maybe_existq(type_params,
-	%	  closure_layout->MR_closure_arg_pseudo_type_info[<ArgNum>],
+	%	  closure_layout->MR_closure_arg_pseudo_type_info[<ArgNum> - 1],
 	%         NULL, NULL, &allocated_memory_cells);
 	%
 	%	private_builtin__gc_trace_1_0(type_info, &<VarName>);
@@ -1120,7 +1120,7 @@
 			target_code_input(lval(ClosureArgLval)),
 			raw_target_code(string__format(
 			    ")->MR_closure_layout->" ++
-			    "MR_closure_arg_pseudo_type_info[%d],\n\t" ++
+			    "MR_closure_arg_pseudo_type_info[%d - 1],\n\t" ++
 			    "NULL, NULL, &allocated_mem);\n",
 				[i(ArgNum)]), [])
 		])),
diff -u compiler/ml_code_gen.m compiler/ml_code_gen.m
--- compiler/ml_code_gen.m
+++ compiler/ml_code_gen.m
@@ -1412,7 +1412,7 @@
 		{ ml_gen_info_get_varset(MLDSGenInfo, VarSet) },
 		{ VarName = ml_gen_var_name(VarSet, Var) },
 		ml_gen_box_or_unbox_lval(HeadType, BodyType, HeadVarLval,
-			VarName, Context, no, BodyLval, ConvDecls,
+			VarName, Context, no, 0, BodyLval, ConvDecls,
 			ConvInputStatements, ConvOutputStatements),
 
 		%
@@ -3016,7 +3016,7 @@
 		ml_variable_type(Var, VarType),
 		ml_gen_var(Var, VarLval),
 		ml_gen_box_or_unbox_lval(VarType, OrigType, VarLval,
-			mlds__var_name(ArgName, no), Context, no,
+			mlds__var_name(ArgName, no), Context, no, 0,
 			ArgLval, ConvDecls, _ConvInputStatements,
 			ConvOutputStatements),
 		% At this point we have an lval with the right type for

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