[m-dev.] diff: fix infinite loop in term__univ_to_term

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 10 22:00:05 AEDT 2000


Estimated hours taken: 0.5

library/term.m:
	Fix a bug reported by Peter Ross:
	there was an infinite loop in term__univ_to_term, since it was
	(indirectly) calling itself recursively with the same argument,
	i.e. the univ itself, rather than the value contained in the univ.

tests/hard_coded/Mmakefile:
tests/hard_coded/term_to_univ_test.m:
tests/hard_coded/term_to_univ_test.exp:
	Add a regression test for this bug.

Workspace: /home/pgrad/fjh/ws/hg
Index: library/term.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term.m,v
retrieving revision 1.96
diff -u -d -r1.96 term.m
--- library/term.m	2000/10/26 05:49:50	1.96
+++ library/term.m	2000/11/10 10:55:11
@@ -605,6 +605,8 @@
 term__type_to_term(Val, Term) :- type_to_univ(Val, Univ),
 	term__univ_to_term(Univ, Term).
 
+	% convert the value stored in the univ (as distinct from
+	% the univ itself) to a term.
 term__univ_to_term(Univ, Term) :-
 	term__context_init(Context),
 	Type = univ_type(Univ),
@@ -655,15 +657,16 @@
 	det_univ_to_type(Univ, TypeInfo),
 	type_info_to_term(Context, TypeInfo, Term).
 term__univ_to_term_special_case("std_util", "univ", [], Univ, Context, Term) :-
+	det_univ_to_type(Univ, NestedUniv),
 	Term = term__functor(term__atom("univ"),
 			% XXX what operator should we use for type
 			% qualification?
 			[term__functor(term__atom(":"),	 % TYPE_QUAL_OP
 				[ValueTerm, TypeTerm],
 				Context)], Context),
-	type_info_to_term(Context, univ_type(Univ), TypeTerm),
-	UnivValue = univ_value(Univ),
-	term__type_to_term(UnivValue, ValueTerm).
+	type_info_to_term(Context, univ_type(NestedUniv), TypeTerm),
+	NestedUnivValue = univ_value(NestedUniv),
+	term__type_to_term(NestedUnivValue, ValueTerm).
 
 term__univ_to_term_special_case("array", "array", [ElemType], Univ, Context, 
 		Term) :-
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.100
diff -u -d -r1.100 Mmakefile
--- tests/hard_coded/Mmakefile	2000/11/06 08:29:10	1.100
+++ tests/hard_coded/Mmakefile	2000/11/10 10:57:54
@@ -106,6 +106,7 @@
 	string_alignment_bug \
 	string_loop \
 	term_io_test \
+	term_to_univ_test \
 	test_imported_no_tag \
 	tim_qual1 \
 	tuple_test \
Index: tests/hard_coded/term_to_univ_test.exp
===================================================================
RCS file: term_to_univ_test.exp
diff -N term_to_univ_test.exp
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ term_to_univ_test.exp	Fri Nov 10 21:58:22 2000
@@ -0,0 +1,2 @@
+functor(atom("univ"), [functor(atom(":"), [functor(integer(4), [], context("", 0)), functor(atom(":"), [functor(atom("int"), [], context("", 0)), functor(atom("int"), [], context("", 0))], context("", 0))], context("", 0))], context("", 0))
+univ(4 : (int : int))
Index: tests/hard_coded/term_to_univ_test.m
===================================================================
RCS file: term_to_univ_test.m
diff -N term_to_univ_test.m
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ term_to_univ_test.m	Fri Nov 10 21:57:41 2000
@@ -0,0 +1,20 @@
+:- module term_to_univ_test.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module term, term_io, varset, std_util.
+
+main -->
+	{ X = 4 },
+	{ type_to_univ(X, Univ0) },
+	{ type_to_univ(Univ0, Univ) },
+	{ term__univ_to_term(Univ, Term) },
+	write(Term), nl,
+	{ varset__init(VarSet) },
+	write_term(VarSet, Term), nl.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list