[m-rev.] for review: extend mutual tail rec optimization to functions

Peter Wang novalazy at gmail.com
Fri Sep 22 15:16:03 AEST 2017


Hi Zoltan,

The compiler generates invalid C code for the attached test case
following this change.

% mmc -s hlc.gc -c test2.m
test2.c: In function ‘test2__test_foo_1_p_0’:
test2.c:633:14: error: ‘succeeded’ undeclared (first use in this function)
       return succeeded;
	      ^
test2.c:633:14: note: each undeclared identifier is reported only once for each function it appears in
test2.c: In function ‘test2__test_bar_1_p_0’:
test2.c:686:14: error: ‘succeeded’ undeclared (first use in this function)
       return succeeded;

Peter
-------------- next part --------------
:- module test2.
:- interface.

:- type foo
    --->    foo(foo)
    ;       bar(bar).

:- type bar
    --->    foo(foo).

:- pred test_foo(foo::in) is semidet.

%--------------------------------------------------------------------%

:- implementation.

test_foo(Foo) :-
    (
        Foo = foo(Foo1),
        test_foo(Foo1)
    ;
        Foo = bar(Bar),
        test_bar(Bar)
    ).

:- pred test_bar(bar::in) is semidet.
:- pragma no_inline(test_bar/1).

test_bar(foo(Foo)) :-
    test_foo(Foo).


More information about the reviews mailing list