[m-rev.] for post-commit review: make mtags generate smaller tags files

Zoltan Somogyi zs at csse.unimelb.edu.au
Wed Sep 2 09:40:19 AEST 2009


I am looking for feedback mostly on whether the default settings are right.
Also, if anyone wants to make the 30 character limit into a parameter, go
ahead after the commit. I don't know perl well enough to do it myself.

Zoltan.

--------------------------------------------------------------------------

The tags file for the compiler directory is 14.8 megabytes in size,
which is a problem for e.g. laptops with limited disk capacity. Much of this
size is accounted for by entries that do not seem useful. This diff allows
the contents of the tags file to be controlled better. With the new defaults,
compiler/tags is now a bit less than half its previous size (7.1 Mb), with no
significant loss of amenity.

scripts/mtags.in:
	Add options to mtags to control which module qualified tags it
	generates entries for. These options control this in two dimenions.

	The first dimension is whether mtags will generate tags using "__"
	as well as "." as the module qualifier. If the user specifies the
	new option --underscore-qualified-names, mtags does; by default,
	it doesn't.

	Given a fully qualified name, the second dimension controls
	which versions of it mtags generates entries for. The old behavior
	was to generate entries for the fully qualified name, for the
	unqualified name, and for all the partially qualified versions in
	between in which the missing qualifiers were a prefix of the fully
	qualified name.

	This behavior can still be obtained by specifying the new option
	--all-module-qualified-names.

	The new option --no-module-qualified-names" makes mtags not generate
	entries for any fully or partially module qualified names, generating
	entries only for the unqualified names. (With this, and no "__"
	qualified names, compiler/tags is only 4.5 Mb in size.)

	The default is to always generate entries for unqualified names, but
	generate entries for partially or fully qualified names only if they
	are 30 characters or less in length. This means that we generate
	entries for

		map.search

	but not for

		abstract_mode_constraints.allproc_annotated_constraints

	The rationales for this are that

	- short names are more likely to be ambiguous, and thus require
	  disambiguating module qualifiers at call sites or other reference
	  sites, and

	- references to long names are unlikely to be module qualified simply
	  because the qualified name is likely to lead to excessively long
	  lines.

scripts/Mmakefile:
	Fix an old annoyance: do not sprinkle garbage into the output
	when rebuilding mtags.

cvs diff: Diffing .
Index: Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/Mmakefile,v
retrieving revision 1.44
diff -u -b -r1.44 Mmakefile
--- Mmakefile	26 Feb 2008 15:15:04 -0000	1.44
+++ Mmakefile	31 Aug 2009 16:23:55 -0000
@@ -69,14 +69,20 @@
 	@for file in $(CONF_SCRIPTS) ; do \
 		if test "$*" = "$$file" ; then \
 			$(MERCURY_DIR)/config.status --file=$* ; \
-			if grep -n '[^$$]@' $@; then false; else true; fi ; \
+			if grep -n '[^$$]@' $@ > /dev/null; \
+			then false; \
+			else true; \
+			fi ; \
 			chmod a+x $* ; \
 		fi \
 	done
 	@for file in $(CONF_FILES) $(CONF_DEBUG_SCRIPTS) ; do \
 		if test "$*" = "$$file" ; then \
 			$(MERCURY_DIR)/config.status --file=$* ; \
-			if grep -n '[^$$]@' $@; then false; else true; fi \
+			if grep -n '[^$$]@' $@ > /dev/null; \
+			then false; \
+			else true;
+			fi \
 		fi \
 	done
 
Index: mtags.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/mtags.in,v
retrieving revision 1.5
diff -u -b -r1.5 mtags.in
--- mtags.in	22 Jul 2009 02:07:14 -0000	1.5
+++ mtags.in	31 Aug 2009 16:12:48 -0000
@@ -1,5 +1,5 @@
 #!@PERL@ -w
-# vim: ts=4 sw=4 et
+# vim: ts=4 sw=4 et ft=perl
 #---------------------------------------------------------------------------#
 # Copyright (C) 1994-2001, 2003, 2005-2007 The University of Melbourne.
 # This file may only be copied under the terms of the GNU General
@@ -91,6 +91,20 @@
         Do not output extra commands to allow searching for
         definitions.
 
+    --all-module-qualified-names
+        Generate tags for all fully or partially qualified names. The default
+        is to generate tags only if they are reasonably short, which is
+        currently defined as being 30 characters or less using \`.' as
+        the module name separator.
+
+    --no-module-qualified-names
+        Generate tags only for unqualified names.
+
+    --underscore-qualified-names
+        When generating tags for fully or partially module qualified names,
+        generate tags using \`__' as well as \`.' as the module name separator.
+        The default is to use only \`.' as module name separator.
+
     --no-extended-attributes
         Do not output the extra tag attributes for vim/elvis.
 
@@ -135,6 +149,11 @@
 $extended_attributes = "vim";
 $keep_dups = 1;
 $search_definitions = 1;
+$module_qualified_names = 1;
+$all_module_qualified_names = 0;
+# $all_module_qualified_names is meaningful
+# only if $module_qualified_names = 1.
+$underscore_qualified_names = 0;
 $debug = 0;
 
 OPTION:
@@ -192,6 +211,22 @@
         shift(@ARGV);
         next OPTION;
     }
+    if ($ARGV[0] eq "--all-module-qualified-names") {
+        $module_qualified_names = 1;
+        $all_module_qualified_names = 1;
+        shift(@ARGV);
+        next OPTION;
+    }
+    if ($ARGV[0] eq "--no-module-qualified-names") {
+        $module_qualified_names = 0;
+        shift(@ARGV);
+        next OPTION;
+    }
+    if ($ARGV[0] eq "--underscore-qualified-names") {
+        $underscore_qualified_names = 1;
+        shift(@ARGV);
+        next OPTION;
+    }
     if ($ARGV[0] eq "--no-extended-attributes") {
         $extended_attributes = "none";
         shift(@ARGV);
@@ -251,30 +286,51 @@
     $src_name = $name;
     $name =~ s|\.|__|g;     # replace `.' module qualifiers with `__'
 
+    if ($module_qualified_names) {
     # Output a tag for the fully-qualified name.
     if (substr($name, 0, length($module)) ne $module) {
         $name = "${module}__$name";
     }
-    output_single_name();
+        output_single_module_qualified_name();
 
     # Strip off the leading module qualifiers one by one, and output a tag
     # for each partially qualified or unqualified name.
     while ($name =~ /__/) {
         $name =~ s/[^_]*(_[^_]+)*__//;
-        output_single_name();
+            output_single_module_qualified_name();
+        }
+    } else {
+        # Strip off any leading module qualifiers one by one, and output a tag
+        # only for the unqualified name.
+        while ($name =~ /__/) {
+            $name =~ s/[^_]*(_[^_]+)*__//;
+        }
+        output_single_tag();
     }
 }
 
-sub output_single_name() {
+sub output_single_module_qualified_name() {
+    if ($name =~ /__/) {
+        # $name is module qualified.
+
+        $underscore_name = $name;
+        $name =~ s/__/./g;
+        $dot_name = $name;
+        if ($all_module_qualified_names || length($dot_name) < 31) {
     # Output tag using `__' as module qualifier.
+            if ($underscore_qualified_names) {
+                $name = $underscore_name;
     output_single_tag();
+            }
 
     # Output tag using `.' as module qualifier.
-    if ($name =~ /__/) {
-        $save_name = $name;
-        $name =~ s/__/./g;
+            $name = $dot_name;
+            output_single_tag();
+        }
+        $name = $underscore_name;
+    } else {
+        # $name is unqualified.
         output_single_tag();
-        $name = $save_name;
     }
 }
 
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list