Files
mercury/tests/hard_coded/any_call_hoist_bug.m
Peter Wang 88047bbb45 Delete Erlang from tests.
tests/general/float_test.exp3:
tests/general/float_test.m:
tests/general/read_dir_regression.exp4:
tests/general/read_dir_regression.m:
tests/hard_coded/remove_file.exp2:
tests/hard_coded/remove_file.m:
    Delete Erlang backend specific expected outputs.

tests/hard_coded/Mmakefile:
tests/hard_coded/erlang_deconstruct.exp:
tests/hard_coded/erlang_deconstruct.m:
tests/hard_coded/existential_list.exp:
tests/hard_coded/existential_list.m:
tests/valid/Mmakefile:
tests/valid/erl_ite_vars.m:
tests/valid/zf_erlang_bug.m:
    Delete erlang target specific tests.

tests/*:
    Delete Erlang foreign procs and foreign types.
2020-10-27 11:10:11 +11:00

81 lines
2.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%---------------------------------------------------------------------------%
%
% rotd-2006-06-30 and before incorrectly hoisted the method call
% new_literal/1 in the function literal_list/1. The problem was that
% loop invariant hoisting was considering calls (and generic_calls) with
% modes that contained an inst `any' component as candidates for hoisting.
%
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- module any_call_hoist_bug.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module pair.
%---------------------------------------------------------------------------%
:- typeclass foo(L) where [
pred new_literal(L::oa) is det
].
:- instance foo(literal) where [
new_literal(A) :- make_new_literal(A)
].
:- type lit_list(L) == list(pair(int, L)).
main(!IO) :-
LitList0 = literal_list(5) : lit_list(literal),
LitList = cast_to_ground(LitList0),
io.write(LitList, !IO).
:- func literal_list(int::in) = (lit_list(L)::oa) is det <= foo(L).
literal_list(N) = LitList :-
( if N =< 0 then
LitList = []
else
new_literal(A), % XXX This is incorrectly hoisted.
LitList0 = literal_list(N - 1),
LitList = [ N - A | LitList0 ]
).
:- mutable(literal_supply, int, 561, ground, [untrailed]).
:- solver type literal
where representation is int.
:- pred make_new_literal(literal::oa) is det.
make_new_literal(NewLiteral) :-
promise_pure (
semipure get_literal_supply(NextLiteral),
impure set_literal_supply(NextLiteral + 1),
impure NewLiteral = 'representation to any literal/0'(NextLiteral)
).
:- func cast_to_ground(T::ia) = (T::out) is det.
:- pragma foreign_proc("C",
cast_to_ground(A::ia) = (B::out),
[promise_pure, will_not_call_mercury],
"
B = A;
").
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%