[erlang-questions] Compiler and tautologies

Michal Ptaszek <>
Thu Mar 19 09:09:22 CET 2009


Hi!

I suppose it does so. Let's check it out:

f() ->
    case test of
	test ->
	    ok
    end.

f2() ->
    ok.

Then try to compile it to the assembler code:
 compile:file("test", ['S']).
{ok,test}

And check out the test.S file:
{function, f, 0, 2}.
  {label,1}.
    {func_info,{atom,test},{atom,f},0}.
  {label,2}.
    {move,{atom,ok},{x,0}}.
    return.


{function, f2, 0, 4}.
  {label,3}.
    {func_info,{atom,test},{atom,f2},0}.
  {label,4}.
    {move,{atom,ok},{x,0}}.
    return.

The functions' bodies are exactly the same.


----- "Adam Lindberg" <> wrote:

> Hi!
> 
> Does the Erlang compiler optimize code such as:
> 
> f() -> case true of true -> ok end.
> 
> To this?
> 
> f() -> ok.
> 
> 
> 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.
> 
> 
> Cheers,
> Adam

Regards,
-- 
Michal Ptaszek
www.erlang-consulting.com



More information about the erlang-questions mailing list