1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
%%% -*- erlang-indent-level: 2 -*-
%%%-------------------------------------------------------------------
%%% Author: Kostis Sagonas
%%%
%%% Contains tests that depend on the compiler inliner being turned on.
%%%-------------------------------------------------------------------
-module(basic_inline_function).
-export([test/0]).
-compile({inline, [{to_objects, 3}]}).
test() ->
ok = test_inline_match(),
ok.
%%--------------------------------------------------------------------
test_inline_match() ->
bad_object = test1(a, {binary, foo, set}, c),
bad_object = test2(a, {binary, foo, set}, c),
bad_object = test3(a, {binary, foo, set}, c),
ok.
%% Inlined
test1(KeysObjs, C, Ts) ->
case catch to_objects(KeysObjs, C, Ts) of
{'EXIT', _} ->
bad_object;
ok ->
ok
end.
%% "Inlined" by hand
test2(KeysObjs, C, _Ts) ->
case catch (case C of
{binary, _, set} ->
<<_ObjSz0:32, _T/binary>> = KeysObjs;
_ -> ok
end) of
{'EXIT', _} ->
bad_object;
ok ->
ok
end.
%% Not inlined
test3(KeysObjs, C, Ts) ->
case catch fto_objects(KeysObjs, C, Ts) of
{'EXIT', _} ->
bad_object;
ok ->
ok
end.
%% Inlined.
to_objects(Bin, {binary, _, set}, _Ts) ->
<<_ObjSz0:32, _T/binary>> = Bin,
ok;
to_objects(<<_ObjSz0:32, _T/binary>> ,_, _) ->
ok;
to_objects(_Bin, _, _Ts) ->
ok.
%% Not Inlined.
fto_objects(Bin, {binary, _, set}, _Ts) ->
<<_ObjSz0:32, _T/binary>> = Bin,
ok;
fto_objects(<<_ObjSz0:32, _T/binary>> ,_,_) ->
ok;
fto_objects(_Bin, _, _Ts) ->
ok.
|