[m-rev.] fix bug with --high-level-data & .NET back-end

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 8 21:54:00 AEDT 2001


On 08-Nov-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> I've tested this change by bootchecking it in both the
> `hlc.gc' and `hl.gc' grades.  I'll do some more testing
> of the `ilc' and `il' grades before committing it.

Good thing I did, since there were a couple of problems:
I wasn't handling closures correctly,
and I'd forgotten to box the secondary tag field in --low-level-data grades.

Here's a relative diff.  I'll go ahead and commit this now.

--- CHANGES.old	Thu Nov  8 21:46:56 2001
+++ CHANGES14	Thu Nov  8 21:47:37 2001
@@ -37,2 +37,5 @@
 	Improve the comments.
 
+compiler/mlds_to_c.m:
+	Avoid generating some unnecessary casts.
+
diff -u ml_unify_gen.m ml_unify_gen.m
--- ml_unify_gen.m
+++ ml_unify_gen.m
@@ -577,13 +577,13 @@
 	{ Offset = ml_closure_arg_offset },
 	{ list__length(ArgVars, NumArgs) },
 	ml_gen_closure_wrapper(PredId, ProcId, Offset, NumArgs,
-		Context, WrapperFuncRval, WrapperFuncType),
+		Context, WrapperFuncRval0, WrapperFuncType0),
 
 	%
 	% Compute the rval which holds the number of arguments
 	%
-	{ NumArgsRval = const(int_const(NumArgs)) },
-	{ NumArgsType = mlds__native_int_type },
+	{ NumArgsRval0 = const(int_const(NumArgs)) },
+	{ NumArgsType0 = mlds__native_int_type },
 
 	%
 	% the pointer will not be tagged (i.e. the tag will be zero)
@@ -595,7 +595,13 @@
 
 	%
 	% put all the extra arguments of the closure together
+	% Note that we need to box these arguments, except for
+	% the closure layout, which is already a reference type.
 	%
+	{ NumArgsRval = unop(box(NumArgsType0), NumArgsRval0) },
+	{ NumArgsType = mlds__generic_type },
+	{ WrapperFuncRval = unop(box(WrapperFuncType0), WrapperFuncRval0) },
+	{ WrapperFuncType = mlds__generic_type },
 	{ ExtraArgRvals = [ClosureLayoutRval, WrapperFuncRval, NumArgsRval] },
 	{ ExtraArgTypes = [ClosureLayoutType, WrapperFuncType, NumArgsType] },
 
@@ -706,11 +712,7 @@
 	% allocate some fresh type variables to use as the Mercury types
 	% of the boxed arguments
 	%
-	{ varset__init(TypeVarSet0) },
-	{ varset__new_vars(TypeVarSet0, ProcArity, ProcBoxedArgTypeVars,
-		_TypeVarSet) },
-	{ term__var_list_to_term_list(ProcBoxedArgTypeVars,
-		ProcBoxedArgTypes) },
+	{ ProcBoxedArgTypes = ml_make_boxed_types(ProcArity) },
 
 	%
 	% compute the parameters for the wrapper function
@@ -1059,10 +1061,28 @@
 	% 
 	% If there is a secondary tag, it goes in the first field
 	%
+	=(Info),
 	{ MaybeSecondaryTag = yes(SecondaryTag) ->
 		HasSecTag = yes,
-		SecondaryTagRval = const(int_const(SecondaryTag)),
-		SecondaryTagType = mlds__native_int_type,
+		SecondaryTagRval0 = const(int_const(SecondaryTag)),
+		SecondaryTagType0 = mlds__native_int_type,
+		%
+		% With the low-level data representation,
+		% all fields -- even the secondary tag --
+		% are boxed, and so we need box it here.
+		%
+		ml_gen_info_get_module_info(Info, ModuleInfo),
+		module_info_globals(ModuleInfo, Globals),
+		globals__lookup_bool_option(Globals, highlevel_data,
+			HighLevelData),
+		( HighLevelData = no ->
+			SecondaryTagRval = unop(box(SecondaryTagType0),
+					SecondaryTagRval0),
+			SecondaryTagType = mlds__generic_type
+		;
+			SecondaryTagRval = SecondaryTagRval0,
+			SecondaryTagType = SecondaryTagType0
+		),
 		ExtraRvals = [SecondaryTagRval],
 		ExtraArgTypes = [SecondaryTagType]
 	;
@@ -1122,8 +1142,9 @@
 				ArgTypes, Type, ModuleInfo)
 		;
 			% it's a closure
-			% XXX FIXME do we need to box the arguments here?
-			ConsArgTypes = ArgTypes
+			% in this case, the arguments are all boxed
+			ConsArgTypes = ml_make_boxed_types(
+					list__length(ArgTypes))
 		},
 		ml_gen_cons_args(ArgLvals, ArgTypes, ConsArgTypes, ArgModes,
 			ModuleInfo, ArgRvals0, MLDS_ArgTypes0),
@@ -1359,11 +1380,8 @@
 			% care about at this point is whether something is
 			% a type variable or not, not which type variable it
 			% is.
-			varset__init(VarSet0),
-			varset__new_vars(VarSet0, list__length(ArgTypes),
-				ConsArgTypeVars, _VarSet),
-			term__var_list_to_term_list(ConsArgTypeVars,
-				ConsArgTypes)
+			ConsArgTypes = ml_make_boxed_types(
+					list__length(ArgTypes))
 		;
 			% type_util__get_cons_defn shouldn't have failed
 			unexpected(this_file,
@@ -1411,12 +1429,18 @@
 		{ ConstDefns = [] }
 	;
 		%
-		% We need to handle floats specially,
+		% For the MLDS->C and MLDS->asm back-ends,
+		% we need to handle floats specially,
 		% since boxed floats normally get heap allocated,
 		% whereas for other types boxing is just a cast
 		% (casts are OK in static initializers,
 		% but calls to malloc() are not).
 		%
+		% [For the .NET and Java back-ends,
+		% this code currently never gets called,
+		% since currently we don't support static
+		% ground term optimization for those back-ends.]
+		%
 		{ Type = mercury_type(term__functor(term__atom("float"),
 				[], _), _, _)
 		; Type = mlds__native_float_type
@@ -1790,10 +1814,7 @@
 		{ list__length(ArgTypes, TupleArity) }
 	->
 		% The argument types for tuples are unbound type variables.
-		{ varset__init(TypeVarSet0) },
-		{ varset__new_vars(TypeVarSet0, TupleArity,
-			TVars, _TypeVarSet) },
-		{ term__var_list_to_term_list(TVars, FieldTypes) },
+		{ FieldTypes = ml_make_boxed_types(TupleArity) },
 		{ Fields = list__map(MakeUnnamedField, FieldTypes) }
 	;
 		=(Info),
@@ -2251,6 +2272,20 @@
 	;
 		error("ml_gen_field_id: invalid type")
 	).
+
+%-----------------------------------------------------------------------------%
+
+	%
+	% allocate some fresh type variables to use as the Mercury types
+	% of boxed objects
+	%
+:- func ml_make_boxed_types(arity) = list(prog_type).
+ml_make_boxed_types(Arity) = BoxedTypes :-
+	varset__init(TypeVarSet0),
+	varset__new_vars(TypeVarSet0, Arity, BoxedTypeVars, _TypeVarSet),
+	term__var_list_to_term_list(BoxedTypeVars, BoxedTypes).
+
+%-----------------------------------------------------------------------------%
 
 :- func this_file = string.
 this_file = "ml_unify_gen.m".
diff -u mlds_to_c.m mlds_to_c.m
--- mlds_to_c.m
+++ mlds_to_c.m
@@ -2838,6 +2838,13 @@
 	
 mlds_output_boxed_rval(Type, Exprn) -->
 	(
+		{ Type = mlds__generic_type
+		; Type = mlds__mercury_type(_, polymorphic_type, _)
+		}
+	->
+		% It already has type MR_Box, so no cast is needed
+		mlds_output_rval(Exprn)
+	;
 		{ Exprn = unop(cast(OtherType), InnerExprn) },
 		{ Type = OtherType }
 	->
-- 
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