[m-rev.] Re: for review: default modes for higher-order func insts

David Overton dmo at cs.mu.OZ.AU
Fri Oct 12 15:15:32 AEST 2001


On Fri, Oct 12, 2001 at 12:30:37PM +1000, Fergus Henderson wrote:
> On 12-Oct-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > It would be a good idea to move the invalid code that you
> > deleted here to a new test case in tests/invalid,
> > and put an XXX comment in tests/invalid/Mmakefile
> > saying that we don't pass it yet (and explaining why).
> > 
> > That way, this test won't get forgotten.
> 
> I forgot to say: apart from the issue above, this all looks fine now.

Okay, I've added that test case plus the one Simon posted.  Here is the
final log message.  I'll commit this now.


Estimated hours taken: 8.5
Branches: main

Implement a change to the mode system suggested by Ralph Becket to make use of
higher order functions a bit easier.

During mode checking of higher order calls, if the variable being called has a
higher-order function type, but only a ground inst with no higher-order
information, assume that it has the default function modes.

Also, when doing anything that might cause a variable's inst to lose higher
order mode information, report a mode error if the variable has a non-standard
higher order function mode.  Situations where this may occur are at call sites,
exit sites and when merging insts at the end of a branched goal.

Note that because of this restriction, this change is not backwards compatible.

compiler/inst_util.m:
	Define some predicates to check for and produce pred_inst_infos for
	default function modes.
	In 'inst_merge', ensure that higher order inst information is not lost
	from non-standard function insts.

compiler/inst_match.m:
	In 'inst_matches_initial' and 'inst_matches_final', ensure that higher
	order inst information is not lost from non-standard function insts.
	Also allow 'inst_matches_{initial,final,binding}' to succeed
	where the first inst is a standard function inst and the
	second is ground.

compiler/modecheck_call.m:
	In 'modecheck_higher_order_call', if the variable to be called has no
	pred_inst_info, but the correct higher-order function type, assume it
	has the default function modes. 

mode_util.m:
pd_util.m:
	Before replacing a ground inst with 'ground(Uniq, none)', ensure that it
	does not contain any nonstandard function insts.

tests/hard_coded/Mmakefile:
tests/hard_coded/ho_func_default_inst.m:
tests/hard_coded/ho_func_default_inst.exp:
tests/invalid/Mmakefile:
tests/invalid/ho_default_func_1.m:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.m:
tests/invalid/ho_default_func_2.err_exp:
tests/invalid/ho_default_func_3.m:
tests/invalid/ho_default_func_3.err_exp:
	Add some test cases.

tests/invalid/Mmakefile:
tests/invalid/ho_default_func_4.m:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/inst_matches_final_bug.m:
tests/invalid/inst_matches_final_bug.err_exp:
	Add some test cases which we do not yet pass due to a bug in
	inst_matches_final.

NEWS:
doc/reference_manual.tex:
	Document the change.


diff -u tests/invalid/Mmakefile tests/invalid/Mmakefile
--- tests/invalid/Mmakefile
+++ tests/invalid/Mmakefile
@@ -137,6 +137,9 @@
 #			the type class name should be in quotes)
 #	typeclass_mode_{2,3,4}.m (compiler calls error/1)
 #	cyclic_typeclass.m (compiler goes into an infinite loop)
+#	ho_default_func_4.m (due to a bug in the mode-checker ---
+#			see XXX comment in inst_match:inst_matches_final_3)
+#	inst_matches_final_bug.m (due to same bug as ho_default_func_4.m)
 
 # Inter-module optimization changes the diagnostics for some
 # tests (in most cases reporting diagnostics when writing the `.opt'
only in patch2:
--- tests/invalid/inst_matches_final_bug.m	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/inst_matches_final_bug.m	12 Oct 2001 04:44:06 -0000
@@ -0,0 +1,38 @@
+:- module inst_matches_final_bug.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- inst two_to_six == bound(2;3;4;5;6).
+
+main -->
+	call_with_two_to_six(return_three).
+
+:- func return_three = int.
+:- mode return_three = out(bound(3)) is det.
+
+return_three = return_three_2.
+
+:- func return_three_2 = int.
+
+return_three_2 = 1.
+
+:- pred call_with_two_to_six(int::in(two_to_six),
+		io__state::di, io__state::uo) is det.
+:- pragma no_inline(call_with_two_to_six/3).
+
+call_with_two_to_six(2) -->
+	io__write_string("Got two\n").
+call_with_two_to_six(3) -->
+	io__write_string("Got three\n").
+call_with_two_to_six(4) -->
+	io__write_string("Got four\n").
+call_with_two_to_six(5) -->
+	io__write_string("Got five\n").
+call_with_two_to_six(6) -->
+	io__write_string("Got six\n").
only in patch2:
--- tests/invalid/ho_default_func_4.m	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/ho_default_func_4.m	12 Oct 2001 04:41:21 -0000
@@ -0,0 +1,36 @@
+% Compiling this module should generate an error message since
+% it tries to cast a non-standard func inst to ground.
+
+:- module ho_default_func_4.
+
+:- interface.
+:- import_module io.
+
+:- pred main(io__state, io__state).
+:- mode main(di, uo) is det.
+
+:- implementation.
+
+:- import_module int, std_util.
+
+:- inst one == bound(1).
+
+main -->
+	{ baz(foo, F) },
+	io__write_int(F(42)), nl.
+
+:- func foo(int) = int.
+foo(X) = X + 1.
+
+:- func bar(int) = int.
+:- mode bar(in(one)) = out is det.
+bar(X) = X.
+
+:- pred baz(T::in, T::out) is det.
+baz(X, Y) :-
+	( univ_to_type(univ(bar), Y0) ->
+		Y = Y0
+	;
+		Y = X
+	).
+

-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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