mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 13:23:47 +00:00
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.
41 lines
946 B
Mathematica
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;").
|
|
|