[m-rev.] for review: fix bug in term size profiling transformation

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Jan 13 02:34:59 AEDT 2005


For review by Zoltan.

Estimated hours taken: 8
Branches: main

Fix a bug in the compiler that is preventing the compiler
bootstrapping in the term size profiling grades.

compiler/size_prof.m:
	Fix a bug in the code that adds goals to
	to construct typeinfos.  It mishandles
	function types which results in an assertion
	failure in the compiler.

tests/valid/Mmakefile:
tests/valid/size_prof_ho_bug.m
	Test case for the above bug.

Index: compiler/size_prof.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/size_prof.m,v
retrieving revision 1.9
diff -u -r1.9 size_prof.m
--- compiler/size_prof.m	20 Jul 2004 04:41:06 -0000	1.9
+++ compiler/size_prof.m	12 Jan 2005 03:50:39 -0000
@@ -814,7 +814,7 @@
 	; type_to_ctor_and_args(Type, TypeCtor, ArgTypes0) ->
 		canonicalize_type_args(TypeCtor, ArgTypes0, ArgTypes),
 		( ArgTypes = [] ->
-			make_type_ctor_info(TypeCtor, TypeCtorVar,
+			make_type_ctor_info(TypeCtor, [], TypeCtorVar,
 				TypeCtorGoals, !Info),
 			TypeInfoVar = TypeCtorVar,
 			TypeInfoGoals = TypeCtorGoals
@@ -877,7 +877,8 @@
 	list__map2_foldl(make_type_info(Context), ArgTypes,
 		ArgTypeInfoVars, ArgTypeInfoGoalLists, !Info),
 	ArgTypeInfoGoals = list__condense(ArgTypeInfoGoalLists),
-	make_type_ctor_info(TypeCtor, TypeCtorVar, TypeCtorGoals, !Info),
+	make_type_ctor_info(TypeCtor, ArgTypes, TypeCtorVar, TypeCtorGoals,
+		!Info),
 	(
 		CtorIsVarArity = yes,
 		list__length(ArgTypes, Arity),
@@ -916,15 +917,23 @@
 % Return the variable holding the type_ctor_info in TypeCtorVar,
 % and the goals needed to create it in TypeCtorGoals.

-:- pred make_type_ctor_info(type_ctor::in, prog_var::out, list(hlds_goal)::out,
-	info::in, info::out) is det.
+:- pred make_type_ctor_info(type_ctor::in, list(type)::in, prog_var::out,
+	list(hlds_goal)::out, info::in, info::out) is det.

-make_type_ctor_info(TypeCtor, TypeCtorVar, TypeCtorGoals, !Info) :-
+make_type_ctor_info(TypeCtor, TypeArgs, TypeCtorVar, TypeCtorGoals, !Info) :-
 	( map__search(!.Info ^ type_ctor_map, TypeCtor, TypeCtorVarPrime) ->
 		TypeCtorVar = TypeCtorVarPrime,
 		TypeCtorGoals = []
 	;
-		construct_type(TypeCtor, [], Type),
+		(
+			type_ctor_is_higher_order(TypeCtor, Purity,
+				PredOrFunc, EvalMethod)
+		->
+			construct_higher_order_type(Purity, PredOrFunc,
+				EvalMethod, TypeArgs, Type)
+		;
+			construct_type(TypeCtor, [], Type)
+		),
 		VarSet0 = !.Info ^ varset,
 		VarTypes0 = !.Info ^ vartypes,
 		polymorphism__init_const_type_ctor_info_var(Type, TypeCtor,
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.145
diff -u -r1.145 Mmakefile
--- tests/valid/Mmakefile	5 Jan 2005 03:12:28 -0000	1.145
+++ tests/valid/Mmakefile	12 Jan 2005 05:51:26 -0000
@@ -164,6 +164,7 @@
 	shape_type \
 	simplify_bug \
 	simplify_bug2 \
+	size_prof_ho_bug \
 	soln_context \
 	solv \
 	solver_type_bug \
Index: tests/valid/size_prof_ho_bug.m
===================================================================
RCS file: tests/valid/size_prof_ho_bug.m
diff -N tests/valid/size_prof_ho_bug.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/valid/size_prof_ho_bug.m	12 Jan 2005 14:33:04 -0000
@@ -0,0 +1,33 @@
+% This caused the following assertion failure in the term size
+% profiling grades with rotd-2005-01-11 and before:
+%
+%	Uncaught Mercury exception:
+%	Software Error: pred_args_to_func_args: function missing return value?
+%
+% To reproduce the bug, compile with:
+%
+% 	mmc -C --grade asm_fast.gc.tsw size_prof_ho_bug.
+%
+
+:- module size_prof_ho_bug.
+
+:- interface.
+
+:- type version_hash_table.
+
+:- pred set(version_hash_table::in, version_hash_table::out) is det.
+
+:- implementation.
+
+:- type version_hash_table
+	---> ht(
+
+		hash_func  :: ((func) = int),
+		bucket     :: bucket
+	).
+
+:- type bucket ---> bucket.
+
+set(A, B) :-
+	A = ht(F, bucket),
+	B = ht(F, bucket).

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