[m-rev.] diff: add a test case for a bug in ho/type specialization

Julien Fischer juliensf at cs.mu.OZ.AU
Mon May 2 18:17:16 AEST 2005


Estimated hours taken: 6
Branches: main, release

Add a test case for a bug that causes an assertion failure in the
compiler.  It seems to be caused by the interaction of higher-order and
type specialization; a unification involving the construction of a
type_ctor_info (for the type being specialized) in a predicate created
by higher-order specialization seems to have an incorrect entry in the
instmap - this results in simplify incorrectly optimizing away the
unification, even though its output is need later.  (The unification is
the one involving V_20 in the predicate foldl_ho1/5).

This is the same bug that causes the module compiler/mode_robdd.tfeirn
to have to be compiled at a reduced optimization level.  We don't
currently have a fix for this (I'm still working on that), however a
workaround is to disable higher-order specialization for any affected
modules.  (In what is probably another bug, you don't seem to be able to
disable type-specialization, if a predicate has a type_spec pragma on
it).

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/ho_and_type_spec_bug.m:
	A test case that exposes a bug in some of the optimization
	passes.

Julien.

Index: Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mercury.options,v
retrieving revision 1.19
diff -u -r1.19 Mercury.options
--- Mercury.options	20 Apr 2005 12:57:58 -0000	1.19
+++ Mercury.options	2 May 2005 07:58:00 -0000
@@ -41,6 +41,7 @@
 MCFLAGS-foreign_underscore_var	= --halt-at-warn
 MCFLAGS-higher_order4		= -O3
 MCFLAGS-higher_order_implied_mode = -O-1
+MCFLAGS-ho_and_type_spec_bug = -O3
 MCFLAGS-impure_detism           = -O5 --deep-profiling
 MCFLAGS-inhibit_warn_test       = --inhibit-warnings --halt-at-warn
 MCFLAGS-intermod_bug_nested	= --intermodule-optimization
Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.151
diff -u -r1.151 Mmakefile
--- Mmakefile	20 Apr 2005 12:57:58 -0000	1.151
+++ Mmakefile	2 May 2005 07:56:43 -0000
@@ -97,6 +97,7 @@
 	higher_order4 \
 	higher_order5 \
 	higher_order_implied_mode \
+	ho_and_type_spec_bug \
 	ho_func_call \
 	ho_inst \
 	ho_unify \
Index: ho_and_type_spec_bug.m
===================================================================
RCS file: ho_and_type_spec_bug.m
diff -N ho_and_type_spec_bug.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ho_and_type_spec_bug.m	2 May 2005 07:59:15 -0000
@@ -0,0 +1,64 @@
+% Compiling the following program at -O3 causes the following
+% assertion failure in the compiler:
+%
+%	 Uncaught Mercury exception:
+%	 Software Error: map__lookup: key not found
+% 		Key Type: term.var(parse_tree.prog_data.prog_var_type)
+% 		Key Value: var(20)
+% 		Value Type: ll_backend.var_locn.var_state
+%
+:- module ho_and_type_spec_bug.
+
+:- interface.
+
+:- type sparse_bitset(T) ---> [] ; [ int | sparse_bitset(T) ].
+
+:- type robdd(T) ---> robdd(int).
+
+:- type unit ---> unit.
+
+:- pragma type_spec(alpha/4, T = unit).
+:- pred alpha(sparse_bitset(int)::in, robdd(T)::in,
+	robdd(T)::in, robdd(T)::out) is det.
+
+:- implementation.
+
+:- typeclass foo(T) where [
+	func from_int(int) = T
+].
+
+:- instance foo(int) where [
+	from_int(X) = X
+].
+
+alpha(T, E, R0, R) :-
+	Closure = beta(E),
+	foldl(Closure, T, R0, R).
+
+:- pred beta(robdd(T)::in, int::in, robdd(T)::in, robdd(T)::out) is det.
+
+beta(_E, V, _R0, R) :- R = gamma(V).
+
+:- func gamma(int) = robdd(T).
+:- pragma no_inline(gamma/1).
+:- pragma foreign_proc("C",
+	gamma(V::in) = (F::out),
+	[will_not_call_mercury, promise_pure],
+"
+	/* V F */
+").
+
+:- pred foldl(pred(T, U, U), sparse_bitset(T), U, U) <= foo(T).
+:- mode foldl(pred(in, in, out) is det, in, in, out) is det.
+
+foldl(_, [], Acc, Acc).
+foldl(P, [ OffSet | T ], Acc0, Acc) :-
+	fold_bits(P, OffSet, Acc0, Acc1),
+	foldl(P, T, Acc1, Acc).
+
+:- pred fold_bits(pred(T, U, U), int, U, U) <= foo(T).
+:- mode fold_bits(pred(in, in, out) is det, in, in, out) is det.
+
+fold_bits(P, Offset, Acc0, Acc) :-
+ 	Elem = from_int(Offset),
+	P(Elem, Acc0, Acc).

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