[m-rev.] diff: fix structure reuse problems

Peter Wang novalazy at gmail.com
Mon May 9 13:25:48 AEST 2011


On 2011-05-03, Peter Wang <novalazy at gmail.com> wrote:
> Branches: main
> 
> Fix some problems uncovered when trying to build the compiler with
> --structure-reuse enabled, including bug #188.
...
> compiler/structure_reuse.versions.m:
> 	Add a sanity check to unification_set_reuse.

Branches: main

compiler/structure_reuse.versions.m:
	Revert incorrect sanity check in unification_set_reuse.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/reuse_static2.m:
	Add test case.

diff --git a/compiler/structure_reuse.versions.m b/compiler/structure_reuse.versions.m
index 205f685..aacf40f 100644
--- a/compiler/structure_reuse.versions.m
+++ b/compiler/structure_reuse.versions.m
@@ -447,23 +447,23 @@ process_goal(ConvertPotentialReuse, ReuseTable, ModuleInfo, !Goal) :-
 
 unification_set_reuse(ShortReuseDescription, !Unification) :-
     (
-        !.Unification = construct(A, B, C, D, HowToConstruct0, F, G),
+        HowToConstruct0 = !.Unification ^ construct_how,
         ShortReuseDescription = cell_reused(DeadVar, _, PossibleConsIds,
             CellsToUpdate)
     ->
         (
-            HowToConstruct0 = construct_statically,
-            unexpected(this_file, "unification_set_reuse: construct_statically")
+            HowToConstruct0 = construct_statically
+            % Leave static terms as-is.
         ;
-            HowToConstruct0 = construct_dynamically
-        ;
-            HowToConstruct0 = construct_in_region(_)
-        ;
-            HowToConstruct0 = reuse_cell(_)
-        ),
-        CellToReuse = cell_to_reuse(DeadVar, PossibleConsIds, CellsToUpdate),
-        HowToConstruct = reuse_cell(CellToReuse),
-        !:Unification = construct(A, B, C, D, HowToConstruct, F, G)
+            ( HowToConstruct0 = construct_dynamically
+            ; HowToConstruct0 = construct_in_region(_)
+            ; HowToConstruct0 = reuse_cell(_)
+            ),
+            CellToReuse = cell_to_reuse(DeadVar, PossibleConsIds,
+                CellsToUpdate),
+            HowToConstruct = reuse_cell(CellToReuse),
+            !Unification ^ construct_how := HowToConstruct
+        )
     ;
         true
     ).
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index b16f1c3..9b84a3b 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -130,6 +130,7 @@ MCFLAGS-par_saved_const		= -O3 --optimize-saved-vars-const
 MCFLAGS-pred_with_no_modes	= --infer-all
 MCFLAGS-quantifier_warning	= --halt-at-warn
 MCFLAGS-reuse_static		= --ctgc --deforestation
+MCFLAGS-reuse_static2		= --structure-reuse --loop-invariants
 MCFLAGS-sharing_exist		= --ctgc --structure-sharing-widening 1
 MCFLAGS-sharing_loop		= --ctgc --structure-sharing-widening 8
 MCFLAGS-sharing_loop2		= --ctgc --structure-sharing-widening 10
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 263a94f..8613132 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -300,6 +300,7 @@ PAR_CONJ_PROGS = \
 # grades.
 CTGC_PROGS = \
 	reuse_static \
+	reuse_static2 \
 	sharing_exist \
 	sharing_loop \
 	sharing_loop2 \
diff --git a/tests/valid/reuse_static2.m b/tests/valid/reuse_static2.m
new file mode 100644
index 0000000..15fb335
--- /dev/null
+++ b/tests/valid/reuse_static2.m
@@ -0,0 +1,31 @@
+:- module reuse_static2.
+:- interface.
+
+:- import_module maybe.
+
+:- type struct
+    --->    struct(int).
+
+:- pred bad(maybe(struct)::in, maybe(int)::out) is det.
+
+:- implementation.
+
+bad(Maybe, Res) :-
+    (
+	Maybe = yes(This),
+	( if p(This, yes(17)) then
+	    Res = yes(1)
+	else
+	    Res = yes(1)
+	)
+    ;
+	Maybe = no,
+	Res = no
+    ).
+
+:- pred p(struct::in, maybe(int)::out) is det.
+
+p(This, T) :-
+    This = struct(T0),
+    T = yes(T0).
+

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