[m-rev.] for review: fix `:- mutable' decls and sub-modules

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Sep 15 17:34:03 AEST 2005


On Thu, 15 Sep 2005, Julien Fischer wrote:

>
> For review by Ralph.
>
> Estimated hours taken: 10
> Branches: main
>
> Fix the problems with mutable declarations and sub-modules by making
> sure that the relevant information is written out in the private interface
> files.
>
> Fix a bug where mutable variables were not being initialised with their
> declared intial value.  The problem was that the compiler was optimizing away
> the body of the automatically generated predicate that was setting the initial
> value.  We now make such predicates impure to prevent this.
>
> In order to support the above, accept `:- intialise' declarations that specify
> impure predicates, provided that the declaration in question was generated by the
> compiler.  It is still an error for the user to specify such declarations.
>
> Fix some other problems with the code that handles mutable declarations.
>
Here is a relative diff that fixes a few problems with the original
change.

(Update to log message)

tests/hard_coded/not_in_interface.m:
tests/hard_coded/not_in_interface.err_exp.m:
	Test for ordering problems between mutable and initialise
	declarations when emitting errors about items that should
	not occur in module interfaces.  This can happend if
	the item's origin field is incorrectly set.

diff -u compiler/make_hlds_passes.m compiler/make_hlds_passes.m
--- compiler/make_hlds_passes.m	15 Sep 2005 04:56:02 -0000
+++ compiler/make_hlds_passes.m	15 Sep 2005 07:18:32 -0000
@@ -537,9 +537,36 @@
     ),
     module_add_instance_defn(InstanceModuleName, Constraints, Name, Types,
         Body, VarSet, BodyStatus, Context, !ModuleInfo, !IO).
-add_item_decl_pass_2(Item, _Context, !Status, !ModuleInfo, !IO) :-
-    % These are processed during pass 3.
-    Item = initialise(_, _).
+add_item_decl_pass_2(Item, Context, !Status, !ModuleInfo, !IO) :-
+    % These are process properly during pass 3, we just do some
+    % error checking at this point.
+    Item = initialise(Origin, _),
+    !.Status = item_status(ImportStatus, _),
+    ( ImportStatus = exported ->
+        (
+            Origin = user,
+            error_is_exported(Context, "`initialise' declaration", !IO),
+            module_info_incr_errors(!ModuleInfo)
+        ;
+            Origin = compiler(Details),
+            (
+                % Ignore the error if this initialise declaration was
+                % introduced because of a mutable declaration.
+                Details = mutable_decl
+            ;
+                Details = initialise_decl,
+                unexpected(this_file, "Bad introduced intialise declaration.")
+            ;
+                Details = solver_type,
+                unexpected(this_file, "Bad introduced intialise declaration.")
+            ;
+                Details = foreign_imports,
+                unexpected(this_file, "Bad introduced intialise declaration.")
+            )
+        )
+    ;
+        true
+    ).
 add_item_decl_pass_2(Item, Context, !Status, !ModuleInfo, !IO) :-
     Item = mutable(Name, _Type, _InitTerm, _Inst, _MutAttrs),
     !.Status = item_status(ImportStatus, _),
diff -u compiler/modules.m compiler/modules.m
--- compiler/modules.m	15 Sep 2005 06:07:01 -0000
+++ compiler/modules.m	15 Sep 2005 07:30:19 -0000
@@ -1282,9 +1282,18 @@
             module_name_to_file_name(ModuleName, ".int0", no, FileName, !IO),
             io__write_strings(["`", FileName, "' not written.\n"], !IO)
         ;
-                %
-                % Write out the `.int0' file.
-                %
+            %
+            % Write out the `.int0' file.
+            %
+            % XXX The following sequence of operations relies
+            % on the fact that any reversals done while processing
+            % it are undone by subsequent operations.  Also, we
+            % should sort the contents of the .int0 file as we
+            % do for the other types of interface file.  We don't
+            % do that at the moment because the code for doing
+            % that cannot handle the structure of lists of items
+            % that represent private interfaces.
+            %
             strip_imported_items(Items2, [], Items3),
             strip_clauses_from_interface(Items3, Items4),
             handle_mutables_in_private_interface(ModuleName,
only in patch2:
unchanged:
--- tests/invalid/not_in_interface.err_exp	14 Sep 2005 05:26:49 -0000	1.2
+++ tests/invalid/not_in_interface.err_exp	15 Sep 2005 07:26:11 -0000
@@ -1,4 +1,6 @@
 not_in_interface.m:011: Error: `initialise' declaration in module interface.
-not_in_interface.m:015: Error: `pragma' declaration in module interface.
-not_in_interface.m:018: Error: clause for predicate `foo/2' in module
-not_in_interface.m:018:   interface.
+not_in_interface.m:013: Error: `mutable' declaration in module interface.
+not_in_interface.m:015: Error: `initialise' declaration in module interface.
+not_in_interface.m:019: Error: `pragma' declaration in module interface.
+not_in_interface.m:022: Error: clause for predicate `foo/2' in module
+not_in_interface.m:022:   interface.
only in patch2:
unchanged:
--- tests/invalid/not_in_interface.m	5 Sep 2005 03:45:59 -0000	1.1
+++ tests/invalid/not_in_interface.m	15 Sep 2005 07:25:56 -0000
@@ -10,6 +10,10 @@

 :- initialise bar/2.

+:- mutable(hello, int, 42, ground, [untrailed, thread_safe]).
+
+:- initialise bar/2.
+
 :- pred bar(io::di, io::uo) is det.

 :- pragma inline(foo/2).
--------------------------------------------------------------------------
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