[m-rev.] for post-commit review: announce new capabilities of switch detection

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Sep 28 19:29:32 AEST 2005


NEWS:
	Mention the recent expansion in the capabilities of switch detection.

doc/reference_manual.texi:
	Document the recent expansion in the capabilities of switch detection.

tests/hard_codes/switch_detect.{m,exp}:
	Toughen this existing test to make it test what the documentation
	promises: the ability to handle unifications before the inner
	disjunction, and code after the unifications in the inner disjunction.

Zoltan.

cvs diff: Diffing .
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.387
diff -u -b -r1.387 NEWS
--- NEWS	26 Sep 2005 06:52:06 -0000	1.387
+++ NEWS	27 Sep 2005 04:43:26 -0000
@@ -8,6 +8,8 @@
 * The Mercury typeclass system now supports functional dependencies.
 * We now have support for optional module initialisation.
 * We now have support for impure module-local mutable variables.
+* We now have support for recognizing switches in which multiple switch arms
+  have shared code.
 * Support for the old-style lambda, mode and pragma syntax has been removed.
 * ':' is now the type qualification operator, not a module qualifier.
 
@@ -50,6 +52,44 @@
   See the "Module-local mutable variables" section of the Mercury Language
   Reference Manual for details.
 
+* We now have support for recognizing switches in which multiple switch arms
+  have shared code. Where previously programmers had to write code like this
+
+  (
+  	X = a,
+	... code for a ...
+  ;
+  	X = b(...),
+	... code for b ...
+  ;
+  	X = c,
+	... code for c ...
+	... shared code ...
+  ;
+  	X = d(...),
+	... code for d ...
+	... shared code ...
+  )
+
+  to have the disjunction recognized as a switch on X, they can now write
+  code like this:
+
+  (
+  	X = a,
+	... code for a ...
+  ;
+  	X = b(...),
+	... code for b ...
+  ;
+  	(
+		X = c,
+		... code for c ...
+	;
+		X = d(...),
+		... code for d ...
+	),
+	... shared code ...
+  )
 
 Changes to the Mercury standard library:
 
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.328
diff -u -b -r1.328 reference_manual.texi
--- doc/reference_manual.texi	26 Sep 2005 06:52:07 -0000	1.328
+++ doc/reference_manual.texi	27 Sep 2005 02:50:37 -0000
@@ -3280,6 +3280,21 @@
 
 If L is input to the disjunction, then the disjunction is a switch on L.
 
+If two variables are unified with each other,
+then whatever function symbol one variable is unified with,
+the other variable is considered to be unified with the same function symbol.
+In the following example, since K is unified with L,
+the second disjunct unifies L as well as K with cons,
+and thus the disjunction is recognized as a switch.
+
+ at example
+(
+        L = [], empty(Out)
+;
+        K = L, K = [H|T], nonempty(H, T, Out)
+)
+ at end example
+
 A switch can fail
 if the various arms of the switch do not cover
 all the function symbols in the type of the switched-on variable,
@@ -3319,6 +3334,30 @@
         empty(Out), L = []
 ;
         L = [H|T], nonempty(H, T, Out)
+)
+ at end example
+
+The unification of the switched-on variable with a function symbol
+may occur inside a nested disjunction in a given disjunct,
+provided that unification is preceded only by other unifications,
+both inside the nested disjunction and before the nested disjunction.
+The following example is a switch on X, provided X is bound beforehand.
+
+ at example
+(
+        X = f
+	p(Out)
+;
+	Y = X,
+        (
+		Y = g,
+		Intermediate = 42
+	;
+		Z = Y,
+		Z = h(Arg),
+		q(Arg, Intermediate)
+	),
+	r(Intermediate, Out)
 )
 @end example
 
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
Index: tests/hard_coded/switch_detect.exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/switch_detect.exp,v
retrieving revision 1.1
diff -u -b -r1.1 switch_detect.exp
--- tests/hard_coded/switch_detect.exp	2 Sep 2005 05:00:29 -0000	1.1
+++ tests/hard_coded/switch_detect.exp	23 Sep 2005 14:27:09 -0000
@@ -1,2 +1,2 @@
 g(5)
-6
+11
Index: tests/hard_coded/switch_detect.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/switch_detect.m,v
retrieving revision 1.1
diff -u -b -r1.1 switch_detect.m
--- tests/hard_coded/switch_detect.m	2 Sep 2005 04:56:34 -0000	1.1
+++ tests/hard_coded/switch_detect.m	23 Sep 2005 14:44:14 -0000
@@ -10,6 +10,7 @@
 
 :- implementation.
 
+:- import_module int.
 :- import_module require.
 
 :- type t
@@ -32,7 +33,14 @@
 		Y = f,
 		Num = 42
 	;
-		( Y = g(Num) ; Y = h(Num, _) )
+		Z = Y,
+		(
+			Z = g(Num)
+		;
+			W = Z,
+			W = h(Num0, _),
+			Num = Num0 + 5
+		)
 	),
 	io__write_int(Num, !IO),
 	io__nl(!IO).
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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