[m-rev.] diff: type qualify clauses in .opt files

Julien Fischer juliensf at cs.mu.OZ.AU
Mon Oct 17 18:05:04 AEST 2005


Estimated hours taken: 1
Branches: main

Fix an old XXX by making the compiler type qualify clauses in
intermodule-optimization (.opt) files.  This reduces spurious warnings about
type ambiguities when compiling with intermodule-optimization.  Unfortunately
it doesn't quite eliminate the problem, see the BUGS file for an example.

This change increases the total size of the .opt files for the standard library
by about 1.5%.  (Actually we write out quite a lot of redundant information to
these files anyway, duplicate foreign_import_module decls etc, so with a bit
more work it ought to be possible to get most of that increase back.)

configure.in:
	Require the installed compiler to support ':' as a type qualifier.

compiler/intermod.m:
	Type qualify the functors in clauses that we write to .opt files.
	This avoids spurious warnings about type ambiguities.

compiler/hlds_out.m:
	Use ':' in place of `with_type` when writing out clauses.

Julien.

Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.435
diff -u -r1.435 configure.in
--- configure.in	4 Oct 2005 10:34:36 -0000	1.435
+++ configure.in	17 Oct 2005 07:40:23 -0000
@@ -237,8 +237,8 @@

 		q(T, N) :-
 			(
-			 	T = a,
-				N = 0
+			 	T = a : t,
+				N = 0 : int
 			;
 				( T = b ; T = c(_) ),
 				N = 1
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.372
diff -u -r1.372 hlds_out.m
--- compiler/hlds_out.m	12 Oct 2005 01:27:50 -0000	1.372
+++ compiler/hlds_out.m	17 Oct 2005 06:56:27 -0000
@@ -136,7 +136,7 @@
     %
 :- pred write_hlds(int::in, module_info::in, io::di, io::uo) is det.

-    % write_clause(Indent, ModuleInfo, PredId, VarSet, AppendVarNums, HeadVars,
+    % write_clauses(Indent, ModuleInfo, PredId, VarSet, AppendVarNums, HeadVars,
     %   PredOrFunc, Clauses, MaybeVarTypes).
     %
 :- pred write_clauses(int::in, module_info::in, pred_id::in,
@@ -2508,7 +2508,7 @@
         MaybeType = yes(Type),
         TypeQual = yes(TVarSet, _)
     ->
-        io__write_string(" `with_type` ", !IO),
+        io__write_string(" : ", !IO),
         mercury_output_type(TVarSet, AppendVarNums, Type, !IO)
     ;
         true
@@ -2578,7 +2578,7 @@
         MaybeType = yes(Type),
         TypeQual = yes(TVarSet, _)
     ->
-        io__write_string(" `with_type` ", !IO),
+        io__write_string(" : ", !IO),
         mercury_output_type(TVarSet, AppendVarNums, Type, !IO)
     ;
         true
Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.180
diff -u -r1.180 intermod.m
--- compiler/intermod.m	5 Oct 2005 06:33:39 -0000	1.180
+++ compiler/intermod.m	14 Oct 2005 04:08:29 -0000
@@ -1538,6 +1538,7 @@
     clauses_info_varset(ClausesInfo, VarSet),
     clauses_info_headvars(ClausesInfo, HeadVars),
     clauses_info_clauses_only(ClausesInfo, Clauses),
+    clauses_info_vartypes(ClausesInfo, VarTypes),

     ( pred_info_get_goal_type(PredInfo, promise(PromiseType)) ->
         ( Clauses = [Clause] ->
@@ -1547,17 +1548,19 @@
             error("write_preds: assertion not a single clause.")
         )
     ;
+        pred_info_typevarset(PredInfo, TypeVarset),
+        MaybeVarTypes = yes(TypeVarset, VarTypes),
         list__foldl(write_clause(ModuleInfo, PredId, VarSet,
-            HeadVars, PredOrFunc, SymName), Clauses, !IO)
+            HeadVars, PredOrFunc, SymName, MaybeVarTypes), Clauses, !IO)
     ),
     write_preds(ModuleInfo, PredIds, !IO).

 :- pred write_clause(module_info::in, pred_id::in, prog_varset::in,
-    list(prog_var)::in, pred_or_func::in, sym_name::in, clause::in,
-    io::di, io::uo) is det.
+    list(prog_var)::in, pred_or_func::in, sym_name::in,
+    maybe_vartypes::in, clause::in, io::di, io::uo) is det.

 write_clause(ModuleInfo, PredId, VarSet, HeadVars, PredOrFunc, _SymName,
-        Clause0, !IO) :-
+        MaybeVarTypes, Clause0, !IO) :-
     Clause0 = clause(_, _, mercury, _),
     strip_headvar_unifications(HeadVars, Clause0, ClauseHeadVars, Clause),
     % Variable numbers need to be appended for the case
@@ -1565,13 +1568,12 @@
     % are named the same as variables in the enclosing clause.
     AppendVarNums = yes,
     UseDeclaredModes = yes,
-    MaybeVarTypes = no,
     hlds_out__write_clause(1, ModuleInfo, PredId, VarSet, AppendVarNums,
         ClauseHeadVars, PredOrFunc, Clause, UseDeclaredModes, MaybeVarTypes,
         !IO).

 write_clause(ModuleInfo, PredId, VarSet, _HeadVars, PredOrFunc, SymName,
-        Clause, !IO) :-
+        _, Clause, !IO) :-
     Clause = clause(ProcIds, Goal, foreign_language(_), _),
     module_info_pred_info(ModuleInfo, PredId, PredInfo),
     pred_info_procedures(PredInfo, Procs),

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