[m-rev.] for review: fix testing of `ground' matches `bound'

David Overton dmo at cs.mu.OZ.AU
Tue Jul 8 14:59:51 AEST 2003


Hi,

I'd like someone to review this change, particularly the change to
modules.m.  The change makes the handling of type definitions in the
.int2 file consistent with the handling of inst definitions.  It is
prompted by a case similar to that shown in the test case below where
the mode system needs to compare the constructors for an inst with the
constructors for a type, and both are read from an .int2 file.
Previously, the type definition was only written out abstractly,
whereas the inst definition was written in full, thus leading to a mode
error because the constructors for the type weren't available.

I'm not quite sure whether this change is the best way to solve this
problem though.

Estimated hours taken: 1.0
Branches: main

Fixes to allow testing of `ground' matches `bound'.

compiler/modules.m:
	When writing discriminated union types to the .int2 file, write
	out the full type definition rather than an abstract type
	declaration.  This is necessary because a module which
	transitively imports the .int2 file may need to know the
	constructors to allow `ground' to be compared with `bound'
	insts.  See the new test case `transitive_inst_type' for an
	example.

compiler/type_util.m:
	Do not remove module qualifiers from constructors before looking
	them up in the cons table.  Some cons ids only have the
	qualified version in the table.

tests/hard_coded/Mmakefile:
tests/hard_coded/transitive_inst_type.exp:
tests/hard_coded/transitive_inst_type.m:
tests/hard_coded/transitive_inst_type2.m:
tests/hard_coded/transitive_inst_type3.m:
	Add a test case.

tests/invalid/undef_symbol.err_exp:
	Adjust output to remove an error message that no longer occurs
	now that the .int2 file contains the full type definition.

Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.274
diff -u -r1.274 modules.m
--- compiler/modules.m	5 Jun 2003 04:16:20 -0000	1.274
+++ compiler/modules.m	7 Jul 2003 23:55:19 -0000
@@ -6398,7 +6398,12 @@
 		ShortInterfaceKind,
 		type_defn(VarSet, Name, Args, abstract_type, Cond)) :-
 	(
-		TypeDefn = du_type(_, _)
+		TypeDefn = du_type(_, _),
+		% For the `.int2' files, we need the full definitions of
+		% discriminated union types.  Even if the functors for a type
+		% are not used within a module, we may need to know them for
+		% comparing insts, e.g. for comparing `ground' and `bound(...)'.
+		ShortInterfaceKind = int3
 	;
 		TypeDefn = abstract_type
 	;
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.121
diff -u -r1.121 type_util.m
--- compiler/type_util.m	3 Jul 2003 12:11:17 -0000	1.121
+++ compiler/type_util.m	8 Jul 2003 01:43:51 -0000
@@ -1851,14 +1851,8 @@
 
 maybe_get_cons_id_arg_types(ModuleInfo, MaybeType, ConsId0, Arity, MaybeTypes)
 		:-
-	( ConsId0 = cons(SymName, _) ->
-		( SymName = qualified(_, Name) ->
-			% get_cons_id_non_existential_arg_types
-			% expects an unqualified cons_id.
-			ConsId = cons(unqualified(Name), Arity)
-		;
-			ConsId = ConsId0
-		),
+	( ConsId0 = cons(_SymName, _) ->
+		ConsId = ConsId0,
 		(
 			MaybeType = yes(Type),
 
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.199
diff -u -r1.199 Mmakefile
--- tests/hard_coded/Mmakefile	13 Jun 2003 05:39:47 -0000	1.199
+++ tests/hard_coded/Mmakefile	8 Jul 2003 01:12:34 -0000
@@ -150,6 +150,7 @@
 	test_imported_no_tag \
 	tim_qual1 \
 	time_test \
+	transitive_inst_type \
 	tuple_test \
 	tuple_test \
 	type_ctor_desc \
Index: tests/hard_coded/transitive_inst_type.exp
===================================================================
RCS file: tests/hard_coded/transitive_inst_type.exp
diff -N tests/hard_coded/transitive_inst_type.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/transitive_inst_type.exp	8 Jul 2003 01:45:51 -0000
@@ -0,0 +1 @@
+0
Index: tests/hard_coded/transitive_inst_type.m
===================================================================
RCS file: tests/hard_coded/transitive_inst_type.m
diff -N tests/hard_coded/transitive_inst_type.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/transitive_inst_type.m	8 Jul 2003 01:08:30 -0000
@@ -0,0 +1,15 @@
+:- module transitive_inst_type.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module transitive_inst_type2.
+
+main -->
+	{ new_sequence(Seq) },
+	{ sequence_length(Seq, Size) },
+	io__write_int(Size),
+	io__nl.
Index: tests/hard_coded/transitive_inst_type2.m
===================================================================
RCS file: tests/hard_coded/transitive_inst_type2.m
diff -N tests/hard_coded/transitive_inst_type2.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/transitive_inst_type2.m	8 Jul 2003 01:24:09 -0000
@@ -0,0 +1,20 @@
+:- module transitive_inst_type2.
+:- interface.
+
+:- import_module transitive_inst_type3.
+
+:- type sequence == my_list(int).
+:- inst sequence == my_list(ground).
+
+:- pred sequence_length(sequence, int).
+:- mode sequence_length(in(sequence), out) is det.
+
+:- pred new_sequence(sequence).
+:- mode new_sequence(out) is det.
+
+:- implementation.
+
+sequence_length(Seq, Len) :-
+	length(Seq, Len).
+
+new_sequence([]).
Index: tests/hard_coded/transitive_inst_type3.m
===================================================================
RCS file: tests/hard_coded/transitive_inst_type3.m
diff -N tests/hard_coded/transitive_inst_type3.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/transitive_inst_type3.m	8 Jul 2003 01:25:27 -0000
@@ -0,0 +1,16 @@
+:- module transitive_inst_type3.
+:- interface.
+
+:- type my_list(T) ---> [] ; [T | my_list(T)].
+:- inst my_list(I) ---> [] ; [I | my_list(I)].
+
+:- pred length(my_list(T), int).
+:- mode length(in(my_list(ground)), out) is det.
+
+:- implementation.
+
+:- import_module int.
+
+length([], 0).
+length([_ | Xs], N + 1) :-
+	length(Xs, N).
Index: tests/invalid/undef_symbol.err_exp
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/undef_symbol.err_exp,v
retrieving revision 1.3
diff -u -r1.3 undef_symbol.err_exp
--- tests/invalid/undef_symbol.err_exp	17 Jan 2003 05:57:10 -0000	1.3
+++ tests/invalid/undef_symbol.err_exp	7 Jul 2003 23:56:15 -0000
@@ -3,7 +3,4 @@
 undef_symbol.m:019: In clause for predicate `undef_symbol.p/2':
 undef_symbol.m:019:   error: undefined predicate `string.append/3'
 undef_symbol.m:019:   (the module `string' has not been imported).
-undef_symbol.m:025: In clause for predicate `undef_symbol.q/2':
-undef_symbol.m:025:   error: undefined symbol `term.context/2'
-undef_symbol.m:025:   (the module `term' has not been imported).
 For more information, try recompiling with `-E'.
-- 
David Overton                  Uni of Melbourne     +61 3 8344 1354
dmo at cs.mu.oz.au                Monash Uni (Clayton) +61 3 9905 5779
http://www.cs.mu.oz.au/~dmo    Mobile Phone         +61 4 0337 4393
--------------------------------------------------------------------------
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