[m-rev.] diff: fix nested modules accessibility bug

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Mar 6 05:28:24 AEDT 2002


On 06-Mar-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> tests/hard_coded/sub-modules/Mmakefile:
> tests/hard_coded/sub-modules/accessibility.m:
> tests/hard_coded/sub-modules/sub_a.m:
> 	Add a test case showing a bug in the handling
> 	of accessibility checks for nested modules.
> 	The test is not yet enabled, since we do not yet pass it.

... but with the change below, we do.

----------

Estimated hours taken: 4
Branches: main

compiler/modules.m:
	Fix a bug where the accessibility checking for nested modules
	was being done incorrectly.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/accessibility.exp:
	Enable the `accessibility' test case, since we now pass it.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/accessibility2.m:
tests/hard_coded/sub-modules/accessibility2.exp:
tests/invalid/Mmakefile:
tests/invalid/sub_c.m:
tests/invalid/sub_c.err_exp:
	Move the tests/invalid/sub_c.m from the `invalid' directory to the
	`tests/hard_code/sub-modules' directory, since this test case should
	be allowed, not rejected.  Also rename it to `accessibility2',
	since that name better reflects what it is testing.

Workspace: /home/ceres/fjh/mercury
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.220
diff -u -d -r1.220 modules.m
--- compiler/modules.m	24 Feb 2002 11:53:22 -0000	1.220
+++ compiler/modules.m	5 Mar 2002 18:08:57 -0000
@@ -1468,6 +1468,11 @@
 	process_module_short_interfaces_transitively(ReadModules,
 		ImpIndirectImports, ".int2", Module14, Module),
 
+	{ module_imports_get_items(Module, Items) },
+	check_imports_accessibility(ModuleName,
+		IntImportedModules ++ IntUsedModules ++
+		ImpImportedModules ++ ImpUsedModules, Items),
+
 	{ module_imports_get_error(Module, Error) }.
 
 % grab_unqual_imported_modules:
@@ -1542,6 +1547,11 @@
 	process_module_short_interfaces_transitively(ReadModules,
 			ImpIndirectImportDeps, ".int3", Module13, Module),
 
+	{ module_imports_get_items(Module, Items) },
+	check_imports_accessibility(ModuleName,
+		IntImportDeps ++ IntUseDeps ++ ImpImportDeps ++ ImpUseDeps,
+		Items),
+
 	{ module_imports_get_error(Module, Error) }.
 
 %-----------------------------------------------------------------------------%
@@ -4850,9 +4860,7 @@
 			maybe_record_timestamp(Import, Ext, NeedQualifier,
 				MaybeTimestamp, Module0, Module1),
 			{ ModImplementationImports =
-				[Import | ModImplementationImports0] },
-			check_module_accessibility(ModuleName, Import,
-				ModItems0)
+				[Import | ModImplementationImports0] }
 		),
 		{ get_dependencies(Items, IndirectImports1, IndirectUses1) },
 		{ list__append(IndirectImports0, IndirectImports1,
@@ -4869,22 +4877,34 @@
 			Module2, Module)
 	).
 
-:- pred check_module_accessibility(module_name, module_name, item_list,
+:- pred check_imports_accessibility(module_name, list(module_name), item_list,
 				io__state, io__state).
-:- mode check_module_accessibility(in, in, in, di, uo) is det.
+:- mode check_imports_accessibility(in, in, in, di, uo) is det.
 
-check_module_accessibility(ModuleName, ImportedModule, Items) -->
+	%
+	% At this point, we've read in all the appropriate interface files,
+	% including, for every imported/used module, at least the short
+	% interface for that module's parent module, which will contain
+	% the `include_module' declarations for any exported sub-modules
+	% of the parent.  So the accessible sub-modules can be determined
+	% by just calling get_children on the complete item list.
+	%
+	% We then go through all of the imported/used modules,
+	% checking that each one is accessible.
+	%
+check_imports_accessibility(ModuleName, Imports, Items) -->
+	{ get_children(Items, AccessibleSubModules) },
+	list__foldl(check_module_accessibility(ModuleName,
+		AccessibleSubModules, Items), Imports).
+
+:- pred check_module_accessibility(module_name, list(module_name), item_list,
+		module_name, io__state, io__state).
+:- mode check_module_accessibility(in, in, in, in, di, uo) is det.
+
+check_module_accessibility(ModuleName, AccessibleSubModules, Items,
+		ImportedModule) -->
 	( { ImportedModule = qualified(ParentModule, SubModule) } ->
-		%
-		% Check that the imported/used module is accessible,
-		% by searching through the current item list (we should
-		% have already read in the imported module's parent module
-		% at this point, so the item list should include the items
-		% in the parent's interface) looking for an `include_module'
-		% declaration that names it.
-		%
 		(
-			{ get_children(Items, AccessibleSubModules) },
 			{ list__member(ImportedModule, AccessibleSubModules) }
 		->
 			[]
Index: tests/hard_coded/sub-modules/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/sub-modules/Mmakefile,v
retrieving revision 1.5
diff -u -d -r1.5 Mmakefile
--- tests/hard_coded/sub-modules/Mmakefile	5 Mar 2002 17:38:33 -0000	1.5
+++ tests/hard_coded/sub-modules/Mmakefile	5 Mar 2002 18:15:31 -0000
@@ -18,6 +18,8 @@
 #
 
 PROGS=	\
+	accessibility \
+	accessibility2 \
 	use_submodule \
 	parent \
 	parent2 \
@@ -26,12 +28,6 @@
 	nested3 \
 	class \
 	nested_intermod_main
-
-# The following test case is not enabled,
-# because we do not yet pass it:
-#	accessibility
-#		Shows up a bug where the nested module accessibility check
-#		reports some spurious errors.
 
 MCFLAGS-nested_intermod	=	--intermodule-optimization
 MCFLAGS-nested_intermod_main =	--intermodule-optimization
Index: tests/hard_coded/sub-modules/accessibility.exp
===================================================================
RCS file: tests/hard_coded/sub-modules/accessibility.exp
diff -N tests/hard_coded/sub-modules/accessibility.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/accessibility.exp	5 Mar 2002 18:15:39 -0000
@@ -0,0 +1 @@
+Hello.
Index: tests/hard_coded/sub-modules/accessibility2.exp
===================================================================
RCS file: tests/hard_coded/sub-modules/accessibility2.exp
diff -N tests/hard_coded/sub-modules/accessibility2.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/accessibility2.exp	5 Mar 2002 18:15:50 -0000
@@ -0,0 +1 @@
+Hello.
Index: tests/hard_coded/sub-modules/accessibility2.m
===================================================================
RCS file: tests/hard_coded/sub-modules/accessibility2.m
diff -N tests/hard_coded/sub-modules/accessibility2.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/accessibility2.m	5 Mar 2002 18:14:20 -0000
@@ -0,0 +1,19 @@
+
+:- module accessibility2.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module sub_a:sub1.
+:- import_module sub_a.
+
+main -->
+        io__write_string("Hello.\n").
+
+
+
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.103
diff -u -d -r1.103 Mmakefile
--- tests/invalid/Mmakefile	5 Mar 2002 16:55:33 -0000	1.103
+++ tests/invalid/Mmakefile	5 Mar 2002 18:14:31 -0000
@@ -24,7 +24,6 @@
 	ho_default_func_2.sub.m \
 	imported_mode.m \
 	partial_implied_mode.m \
-	sub_b.m \
 	sub_c.m \
 	test_nested.m \
 	transitive_import.m \
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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