[m-rev.] diff: fix bug #229
Peter Wang
novalazy at gmail.com
Wed Nov 23 17:44:21 AEDT 2011
Will commit pending bootcheck.
Branches: main, 11.07
Fix bug #229. A term with an argument produced in a from_ground_term_construct
scope was not itself being marked to be constructed statically. A side-effect
was an exception being thrown while generating a lookup switch in high-level C
grades.
compiler/mark_static_terms.m:
Add the variable constructed in a from_ground_term_construct scope
to the set of static variables.
tests/valid/Mercury.options:
tests/valid/mark_static_bug.m:
Add test case.
diff --git a/compiler/mark_static_terms.m b/compiler/mark_static_terms.m
index 9e0602e..9e8003a 100644
--- a/compiler/mark_static_terms.m
+++ b/compiler/mark_static_terms.m
@@ -67,7 +67,7 @@ goal_mark_static_terms(Goal0, Goal, !SI) :-
GoalExpr0 = conj(ConjType, Goals0),
% It's OK to treat parallel conjunctions as if they were sequential
% here, since if we mark any variables as static, the computation
- %of those variables will be done at compile time.
+ % of those variables will be done at compile time.
conj_mark_static_terms(Goals0, Goals, !SI),
GoalExpr = conj(ConjType, Goals)
;
@@ -87,9 +87,10 @@ goal_mark_static_terms(Goal0, Goal, !SI) :-
GoalExpr = negation(SubGoal)
;
GoalExpr0 = scope(Reason, SubGoal0),
- ( Reason = from_ground_term(_TermVar, from_ground_term_construct) ->
+ ( Reason = from_ground_term(TermVar, from_ground_term_construct) ->
% These scopes already have all their unifications marked
% as construct_statically.
+ set_tree234.insert(TermVar, !SI),
GoalExpr = GoalExpr0
;
goal_mark_static_terms(SubGoal0, SubGoal, !SI),
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index 9b84a3b..c50d775 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -112,6 +112,7 @@ MCFLAGS-livevars_shallow = --no-intermodule-optimization --grade none --trace sh
MCFLAGS-livevars_shallow2 = --no-intermodule-optimization --grade none --trace shallow
MCFLAGS-lco_term = --optimize-constructor-last-call
MCFLAGS-loop_inv_bug = --common-struct --loop-invariants
+MCFLAGS-mark_static_bug = --lookup-switch-size 1
MCFLAGS-mc_bag = --prop-mode-constraints
MCFLAGS-mc_extra_nonlocals = --prop-mode-constraints
MCFLAGS-mc_graph = --prop-mode-constraints
diff --git a/tests/valid/mark_static_bug.m b/tests/valid/mark_static_bug.m
new file mode 100644
index 0000000..cd8d284
--- /dev/null
+++ b/tests/valid/mark_static_bug.m
@@ -0,0 +1,39 @@
+% A term with an argument produced in a from_ground_term_construct scope was
+% not itself being marked to be constructed statically. A side-effect was an
+% exception being thrown while generating a lookup switch in high-level C
+% grades.
+
+:- module mark_static_bug.
+:- interface.
+
+:- type foo
+ ---> foo(int, bar).
+
+:- type bar
+ ---> none
+ ; bar(int, int, int, baz).
+
+:- type baz
+ ---> baz(int).
+
+:- pred mkfoo(int::in, foo::out) is semidet.
+
+:- implementation.
+
+mkfoo(X, Foo) :-
+ (
+ X = 1,
+ Bar = bar(100, 200, 300, baz(400)),
+ Foo = foo(1, Bar)
+ ;
+ X = 2,
+ Foo = foo(2, none)
+ ;
+ X = 3,
+ Foo = foo(3, none)
+ ;
+ X = 4,
+ Foo = foo(4, none)
+ ).
+
+% vim: ft=mercury ts=4 sts=4 sw=4 et
--------------------------------------------------------------------------
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