for review: bug fix for modules.m

Simon Taylor stayl at cs.mu.OZ.AU
Fri Feb 6 16:34:03 AEDT 1998


Hi Fergus,

Could you please review this.


Estimated hours taken: 0.5

Fix a bug reported by Tomas By which caused multiple
definition errors when two modules use a third
module, and one of the modules imports the other.

compiler/modules.m
	Delay processing of short interfaces until all long 
	interfaces have been read to avoid reading both
	the long and short interface for a module.

tests/valid/module_*.m
	Add a test case.

Index: modules.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/modules.m,v
retrieving revision 1.55
diff -u -r1.55 modules.m
--- modules.m	1998/01/29 13:42:46	1.55
+++ modules.m	1998/02/06 04:40:14
@@ -475,8 +475,8 @@
 	{ dir__basename(ModuleName, BaseModuleName) },
 	{ Module1 = module_imports(BaseModuleName, [], [], Items1, no) },
 
-	process_module_interfaces(["mercury_builtin" | ImportedModules], 
-		[], Module1, Module2),
+	process_module_interfaces_2(["mercury_builtin" | ImportedModules], 
+		[], IndirectImports, Module1, Module2),
 	{ Module2 = module_imports(_, Direct2, Indirect2, Items2, Error2) },
 
 		% we add a pseudo-declarations `:- used' at the end
@@ -486,7 +486,8 @@
 		[module_defn(VarSet, used) - Context], Items3) },
 	{ Module3 = module_imports(BaseModuleName, Direct2, Indirect2, 
 		Items3, Error2) },
-	process_module_interfaces(UsedModules, [], Module3, Module),
+	process_module_interfaces(UsedModules, IndirectImports,
+		Module3, Module),
 
 	{ Module = module_imports(_, _, _, _, Error) }.
 
@@ -1516,11 +1517,19 @@
 
 %-----------------------------------------------------------------------------%
 
-process_module_interfaces([], IndirectImports, Module0, Module) -->
-	process_module_short_interfaces(IndirectImports, Module0, Module).
-
-process_module_interfaces([Import | Imports], IndirectImports0, Module0, Module)
-		-->
+process_module_interfaces(Imports, IndirectImports0, Module0, Module) -->
+	process_module_interfaces_2(Imports, IndirectImports0,
+		IndirectImports, Module0, Module1),
+	process_module_short_interfaces(IndirectImports, Module1, Module).
+
+:- pred process_module_interfaces_2(list(string), list(string), 
+	list(string), module_imports, module_imports, io__state, io__state).
+:- mode process_module_interfaces_2(in, in, out, in, out, di, uo) is det.
+
+process_module_interfaces_2([], IndirectImports, IndirectImports, 
+		Module, Module) --> [].
+process_module_interfaces_2([Import | Imports], IndirectImports0,
+		IndirectImports, Module0, Module) -->
 	{ Module0 = module_imports(ModuleName, DirectImports0,
 				OldIndirectImports, Items0, Error0) },
 	(
@@ -1540,13 +1549,13 @@
 				[]
 			)
 		),
-		process_module_interfaces(Imports, IndirectImports0,
-					Module0, Module)
+		process_module_interfaces_2(Imports, IndirectImports0,
+				IndirectImports, Module0, Module)
 	;
 		{ list__member(Import, DirectImports0) }
 	->
-		process_module_interfaces(Imports, IndirectImports0,
-					Module0, Module)
+		process_module_interfaces_2(Imports, IndirectImports0,
+				IndirectImports, Module0, Module)
 	;
 		read_mod_interface(Import,
 			"Reading interface for module", yes, 
@@ -1581,9 +1590,9 @@
 			IndirectImports3) },
 		{ list__append(Items0, Items1, Items2) },
 		{ Module1 = module_imports(ModuleName, DirectImports1, 
-					OldIndirectImports, Items2, Error2) },
-		process_module_interfaces(Imports, IndirectImports3,
-				Module1, Module)
+				OldIndirectImports, Items2, Error2) },
+		process_module_interfaces_2(Imports, IndirectImports3,
+				IndirectImports, Module1, Module)
 	).
 
 %-----------------------------------------------------------------------------%





Index: module_a.m
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/module_a.m,v
retrieving revision 1.1
diff -u -r1.1 module_a.m
--- module_a.m	1998/01/09 12:35:15	1.1
+++ module_a.m	1998/02/06 05:02:42
@@ -1,5 +1,7 @@
+:- module module_a.
 :- interface.
+:- use_module io.
+:- import_module module_e.
 :- use_module module_b.
-
 :- type module_a__foo == module_b__foo.
 
Index: module_b.m
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/module_b.m,v
retrieving revision 1.1
diff -u -r1.1 module_b.m
--- module_b.m	1998/01/09 12:35:15	1.1
+++ module_b.m	1998/02/06 05:03:38
@@ -1,3 +1,4 @@
+:- module module_b.
 :- interface.
 :- use_module module_c.
 :- type module_b__foo == module_c__foo.
Index: module_c.m
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/module_c.m,v
retrieving revision 1.1
diff -u -r1.1 module_c.m
--- module_c.m	1998/01/09 12:35:16	1.1
+++ module_c.m	1998/02/06 04:47:25
@@ -1,3 +1,4 @@
+:- module module_c.
 :- interface.
 :- use_module module_d.
 :- type module_c__foo == module_d__foo.
Index: module_d.m
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/module_d.m,v
retrieving revision 1.1
diff -u -r1.1 module_d.m
--- module_d.m	1998/01/09 12:35:16	1.1
+++ module_d.m	1998/02/06 04:47:32
@@ -1,3 +1,4 @@
+:- module module_d.
 :- interface.
 :- type module_d__foo == int.
 
:- module module_e.

:- interface.

:- use_module io.
:- mode e :: out.



More information about the developers mailing list