Files
mercury/tests/hard_coded/impure_prune.m
Fergus Henderson 6d88f700a7 Fix a couple of bugs related to pruning of impure goals with no output
Estimated hours taken: 1.5

Fix a couple of bugs related to pruning of impure goals with no output
variables.

compiler/det_analysis.m:
	Fix a bug: the compiler was automatically inserting pruning
	across impure goals with no output variables.  That should
	happen only for pure or semipure goals.  To prevent pruning
	in those cases, I changed it so that impure goals with no
	output variables are not considered single-solution contexts.

doc/reference_manual.texi:
	Document the above-mentioned change.

compiler/clause_to_proc.m:
	Fix a bug: when converting a bunch of clauses into a disjunction,
	clause_to_proc.m was not computing the proper purity annotation
	on the goal_info for the disjunction.

tests/hard_coded/Mmakefile:
tests/hard_coded/impure_prune.m:
tests/hard_coded/impure_prune.exp:
	A test case for the above-mentioned changes to det_analysis.m
	and clause_to_proc.m.
1998-10-20 15:07:07 +00:00

41 lines
946 B
Mathematica

:- module impure_prune.
:- interface.
:- import_module io.
:- pred main(state::di, state::uo) is det.
:- implementation.
:- import_module int, require.
:- pragma promise_pure(main/2).
main -->
( { impure do_impure_stuff, fail } ->
{ error("not reached") }
;
{ semipure get_counter(X) },
print("X = "), print(X), nl
).
:- impure pred do_impure_stuff is multi.
do_impure_stuff :-
impure bump_counter.
do_impure_stuff :-
impure bump_counter.
do_impure_stuff :-
impure bump_counter.
:- impure pred bump_counter is det.
bump_counter :-
semipure get_counter(X),
impure set_counter(X + 1).
:- semipure pred get_counter(int::out) is det.
:- impure pred set_counter(int::in) is det.
:- pragma c_header_code("extern Integer counter;").
:- pragma c_code("Integer counter = 0;").
:- pragma c_code(get_counter(X::out), will_not_call_mercury, "X = counter;").
:- pragma c_code(set_counter(X::in), will_not_call_mercury, "counter = X;").