[erlang-questions] Compiler and tautologies

Erik Stenman <>
Thu Mar 19 09:22:26 CET 2009


On 19 mar 2009, at 08.55, Adam Lindberg wrote:

> Hi!
>
> Does the Erlang compiler optimize code such as:
>
> f() -> case true of true -> ok end.
>
> To this?
>
> f() -> ok.

When in doubt try
  erlc -S
Which will give you an .S file:
e.g.
---
-module(f).
-export([f/0]).

f() -> case true of true -> ok end.
---
makrill> erlc -S f.erl
makrill> cat f.S
{module, f}.  %% version = 0
{exports, [{f,0},{module_info,0},{module_info,1}]}.
{attributes, []}.
{labels, 7}.

{function, f, 0, 2}.
   {label,1}.
     {func_info,{atom,f},{atom,f},0}.
   {label,2}.
     {move,{atom,ok},{x,0}}.
     return.

{function, module_info, 0, 4}.
   {label,3}.
     {func_info,{atom,f},{atom,module_info},0}.
   {label,4}.
     {move,{atom,f},{x,0}}.
     {call_ext_only,1,{extfunc,erlang,get_module_info,1}}.

{function, module_info, 1, 6}.
   {label,5}.
     {func_info,{atom,f},{atom,module_info},1}.
   {label,6}.
     {move,{x,0},{x,1}}.
     {move,{atom,f},{x,0}}.
     {call_ext_only,2,{extfunc,erlang,get_module_info,2}}.


>
>
> I'm working with Erlang code generation in a customer's product and  
> I wonder if I need to optimize away such code myself or not.

The compiler does this for you.

/Erik



More information about the erlang-questions mailing list