[m-dev.] diff: fix bugs in compiler/lambda.m

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Feb 9 01:58:23 AEDT 2000


Estimated hours taken: 4

Fix some bugs in lambda.m.

compiler/lambda.m:
	Fix a bug: in some cases (the cases when it avoided
	introducing a new predicate), lambda.m was not setting
	the `address_taken' field correctly.

	A fix for the MLDS back-end: the optimization of
	assuming that the calling convention for `model_det'
	is compatible with the calling convention for `model_non' 
	is not valid if the `--high-level-code' option is set.

	Update an obsolete comment.

compiler/hlds_pred.m:
	Add a new predicate `proc_info_set_address_taken',
	for use by lambda.m.

tests/hard_coded/deep_copy_bug.m:
tests/hard_coded/deep_copy_bug.exp:
	Add some tests to test the above-mentioned bugs.

Workspace: /d-drive/home/hg/fjh/mercury
Index: tests/hard_coded/deep_copy_bug.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/deep_copy_bug.exp,v
retrieving revision 1.4
diff -u -d -r1.4 deep_copy_bug.exp
--- tests/hard_coded/deep_copy_bug.exp	1998/12/04 01:11:11	1.4
+++ tests/hard_coded/deep_copy_bug.exp	2000/02/08 14:39:41
@@ -1 +1,3 @@
 [var(1), var(2), var(3), var(4), var(5), var(6), var(7), var(8), var(9), var(10)]
+[var(1), var(2), var(3), var(4), var(5), var(6), var(7), var(8), var(9), var(10)]
+[42]
Index: tests/hard_coded/deep_copy_bug.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/deep_copy_bug.m,v
retrieving revision 1.1
diff -u -d -r1.1 deep_copy_bug.m
--- tests/hard_coded/deep_copy_bug.m	1997/04/10 16:04:27	1.1
+++ tests/hard_coded/deep_copy_bug.m	2000/02/08 14:39:52
@@ -14,7 +14,10 @@
 
 :- import_module int, std_util, list, term, varset.
 
-main -->
+main --> test1, test2, test3.
+
+:- pred test1(io__state::di, io__state::uo) is det.
+test1 -->
 	{ Lambda = lambda([X::out] is nondet,
 	(
 		varset__init(Varset0),
@@ -24,3 +27,31 @@
 	{ solutions(Lambda, List) },
 	io__write(List),
 	io__write_string("\n").
+
+:- pred test2(io__state::di, io__state::uo) is det.
+test2 -->
+	test2b("blahblah").
+
+:- pred test2b(T::in, io__state::di, io__state::uo) is det.
+test2b(S) -->
+	{ F = foo(S) },
+	{ solutions(F, List) },
+	io__write(List),
+	io__write_string("\n").
+
+:- pred foo(T, var).
+:- mode foo(in, out) is nondet.
+foo(Blah, X) :-
+	varset__init(Varset0),
+	varset__new_vars(Varset0, 10, Vars, _),
+	list__member(X, Vars).
+
+:- pred test3(io__state::di, io__state::uo) is det.
+test3 -->
+	{ solutions((pred(X::out) is nondet :- bar(X)), List) },
+	io__write(List),
+	io__write_string("\n").
+
+:- pred bar(int).
+:- mode bar(out) is det.
+bar(42).

Workspace: /d-drive/home/hg/fjh/mercury
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.70
diff -u -d -r1.70 hlds_pred.m
--- compiler/hlds_pred.m	2000/01/26 02:04:24	1.70
+++ compiler/hlds_pred.m	2000/02/08 14:33:46
@@ -1482,6 +1482,9 @@
 :- pred proc_info_is_address_taken(proc_info, is_address_taken).
 :- mode proc_info_is_address_taken(in, out) is det.
 
+:- pred proc_info_set_address_taken(proc_info, is_address_taken, proc_info).
+:- mode proc_info_set_address_taken(in, in, out) is det.
+
 :- pred proc_info_get_rl_exprn_id(proc_info, maybe(rl_exprn_id)).
 :- mode proc_info_get_rl_exprn_id(in, out) is det.
 
@@ -1960,6 +1963,12 @@
 proc_info_set_maybe_termination_info(ProcInfo0, R, ProcInfo) :-
 	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
 		P, Q, _, S, T, U),
+	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
+		P, Q, R, S, T, U).
+
+proc_info_set_address_taken(ProcInfo0, T, ProcInfo) :-
+	ProcInfo0 = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
+		P, Q, R, S, _, U),
 	ProcInfo  = procedure(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, 
 		P, Q, R, S, T, U).
 
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.59
diff -u -d -r1.59 lambda.m
--- compiler/lambda.m	2000/01/13 06:16:00	1.59
+++ compiler/lambda.m	2000/02/08 13:12:06
@@ -37,8 +37,8 @@
 % Similarly, a lambda expression may not bind any of the type_infos for
 % those variables; that is, none of the non-local variables
 % should be existentially typed (from the perspective of the lambda goal).
-% When we run the polymorphism.m pass before mode checking, this will
-% be checked by mode analysis.  XXX But currently it is not checked.
+% Now that we run the polymorphism.m pass before mode checking, this is
+% also checked by mode analysis.
 %
 % It might be OK to allow the parameters of the lambda goal to be
 % existentially typed, but currently that is not supported.
@@ -373,10 +373,15 @@
 			% Check that the code models are compatible.
 			% Note that det is not compatible with semidet,
 			% and semidet is not compatible with nondet,
-			% since the arguments go in different registers.
-			% But det is compatible with nondet.
+			% since the calling conventions are different.
+			% But if we're using the LLDS back-end
+			% (i.e. not --high-level-code),
+			% det is compatible with nondet.
 		( CodeModel = Call_CodeModel
-		; CodeModel = model_non, Call_CodeModel = model_det
+		; CodeModel = model_non, Call_CodeModel = model_det,
+			module_info_globals(ModuleInfo0, Globals),
+			globals__lookup_bool_option(Globals,
+				highlevel_code, no)
 		),
 			% check that the curried arguments are all input
 		proc_info_argmodes(Call_ProcInfo, Call_ArgModes),
@@ -390,10 +395,17 @@
 		PredId = PredId0,
 		ProcId = ProcId0,
 		PredName = PredName0,
-		ModuleInfo = ModuleInfo0,
 		NumArgVars = NumInitialVars,
 		mode_util__modes_to_uni_modes(CurriedArgModes, CurriedArgModes,
-			ModuleInfo0, UniModes)
+			ModuleInfo0, UniModes),
+		%
+		% we need to mark the procedure as having had its
+		% address taken
+		%
+		proc_info_set_address_taken(Call_ProcInfo, address_is_taken,
+			Call_NewProcInfo),
+		module_info_set_pred_proc_info(ModuleInfo0, PredId, ProcId,
+			Call_PredInfo, Call_NewProcInfo, ModuleInfo)
 	;
 		% Prepare to create a new predicate for the lambda
 		% expression: work out the arguments, module name, predicate

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- 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