[m-dev.] diff: don't put equivalence type definitions in `.int2' files

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Mar 1 22:57:44 AEDT 2001


For the main branch only.

Because this bug fix causes the compiler to diagnose errors that it
didn't before, this may break existing code.  If it does, the fix is
straight-forward, namely add the missing imports.

----------

Estimated hours taken: 5

compiler/modules.m:
	Don't put equivalence type definitions in `.int2' files;
	instead just put the type names (i.e. abstract type declarations)
	in the `.int2' files.  This fixes a bug where we were failing
	to diagnose errors where a module interface referenced a type
	which was not defined in any of the modules that that interface
	imported.

Workspace: /home/venus/fjh/ws-venus3/mercury
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.151
diff -u -d -r1.151 modules.m
--- compiler/modules.m	2001/02/12 11:39:58	1.151
+++ compiler/modules.m	2001/03/01 11:50:24
@@ -895,7 +895,7 @@
 			check_int_for_no_exports(InterfaceItems, ModuleName),
 			write_interface_file(ModuleName, ".int",
 							InterfaceItems),
-			{ get_short_interface(InterfaceItems,
+			{ get_short_interface(InterfaceItems, int2,
 						ShortInterfaceItems) },
 			write_interface_file(ModuleName, ".int2",
 						ShortInterfaceItems),
@@ -911,7 +911,7 @@
 		% only be written to .opt files,
 	{ strip_assertions(InterfaceItems0, InterfaceItems1) },
 	check_for_clauses_in_interface(InterfaceItems1, InterfaceItems),
-	{ get_short_interface(InterfaceItems, ShortInterfaceItems0) },
+	{ get_short_interface(InterfaceItems, int3, ShortInterfaceItems0) },
 	module_qual__module_qualify_items(ShortInterfaceItems0,
 			ShortInterfaceItems, ModuleName, no, _, _, _, _),
 	write_interface_file(ModuleName, ".int3", ShortInterfaceItems),
@@ -4378,11 +4378,15 @@
 	% type declarations, then it doesn't need any import_module
 	% declarations.
 
-:- pred get_short_interface(item_list, item_list).
-:- mode get_short_interface(in, out) is det.
+:- type short_interface_kind
+	--->	int2	% the qualified short interface, for the .int2 file
+	;	int3.	% the unqualified short interface, for the .int3 file
 
-get_short_interface(Items0, Items) :-
-	get_short_interface_2(Items0, [], [], no,
+:- pred get_short_interface(item_list, short_interface_kind, item_list).
+:- mode get_short_interface(in, in, out) is det.
+
+get_short_interface(Items0, Kind, Items) :-
+	get_short_interface_2(Items0, [], [], no, Kind,
 			RevItems, RevImports, NeedsImports),
 	list__reverse(RevItems, Items1),
 	( NeedsImports = yes ->
@@ -4393,13 +4397,13 @@
 	).
 
 :- pred get_short_interface_2(item_list, item_list, item_list, bool,
-				item_list, item_list, bool).
-:- mode get_short_interface_2(in, in, in, in, out, out, out) is det.
+		short_interface_kind, item_list, item_list, bool).
+:- mode get_short_interface_2(in, in, in, in, in, out, out, out) is det.
 
-get_short_interface_2([], Items, Imports, NeedsImports,
+get_short_interface_2([], Items, Imports, NeedsImports, _Kind,
 			Items, Imports, NeedsImports).
 get_short_interface_2([ItemAndContext | Rest], Items0, Imports0, NeedsImports0,
-			Items, Imports, NeedsImports) :-
+			Kind, Items, Imports, NeedsImports) :-
 	ItemAndContext = Item0 - Context,
 	( Item0 = module_defn(_, import(_)) ->
 		Items1 = Items0,
@@ -4409,7 +4413,7 @@
 		Items1 = Items0,
 		Imports1 = [ItemAndContext | Imports0],
 		NeedsImports1 = NeedsImports0
-	; make_abstract_type_defn(Item0, Item1) ->
+	; make_abstract_type_defn(Item0, Kind, Item1) ->
 		Imports1 = Imports0,
 		Items1 = [Item1 - Context | Items0],
 		NeedsImports1 = NeedsImports0
@@ -4422,7 +4426,7 @@
 		Imports1 = Imports0,
 		NeedsImports1 = NeedsImports0
 	),
-	get_short_interface_2(Rest, Items1, Imports1, NeedsImports1,
+	get_short_interface_2(Rest, Items1, Imports1, NeedsImports1, Kind,
 				Items, Imports, NeedsImports).
 
 :- pred include_in_short_interface(item).
@@ -4434,13 +4438,25 @@
 include_in_short_interface(module_defn(_, _)).
 include_in_short_interface(typeclass(_, _, _, _, _)).
 
-:- pred make_abstract_type_defn(item, item).
-:- mode make_abstract_type_defn(in, out) is semidet.
+:- pred make_abstract_type_defn(item, short_interface_kind, item).
+:- mode make_abstract_type_defn(in, in, out) is semidet.
 
-make_abstract_type_defn(type_defn(VarSet, du_type(Name, Args, _, _), Cond),
+make_abstract_type_defn(type_defn(VarSet, du_type(Name, Args, _, _), Cond), _,
 			type_defn(VarSet, abstract_type(Name, Args), Cond)).
-make_abstract_type_defn(type_defn(VarSet, abstract_type(Name, Args), Cond),
+make_abstract_type_defn(type_defn(VarSet, abstract_type(Name, Args), Cond), _,
 			type_defn(VarSet, abstract_type(Name, Args), Cond)).
+make_abstract_type_defn(type_defn(VarSet, eqv_type(Name, Args, _), Cond),
+			ShortInterfaceKind,
+			type_defn(VarSet, abstract_type(Name, Args), Cond)) :-
+	% For the `.int2' files, we need the full definitions of
+	% equivalence types.  They are needed to ensure that
+	% non-abstract equivalence types always get fully expanded
+	% before code generation, even in modules that only indirectly
+	% import the definition of the equivalence type.
+	% But the full definitions are not needed for the `.int3' files.
+	% So we convert equivalence types into abstract types only for
+	% the `.int3' files.
+	ShortInterfaceKind = int3.
 
 	% All instance declarations must be written
 	% to `.int' files as abstract instance

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