NOP in release build of F# code

前端 未结 1 907
鱼传尺愫
鱼传尺愫 2021-01-05 11:35

I am playing with F# in VS2010 beta2, and since I am new to F#, I just picked one of the common examples and went ahead and implemented a factorial function as:



        
相关标签:
1条回答
  • 2021-01-05 12:08

    The maxstack difference is due to the fact that the C# compiler compiles the first method with a «light» method body header, that is used whenever the code is small, has no exceptions and no locals. In that case, the maxstack is not specified and defaults to 8.

    The F# compiler is using a «fat» method body header, and specifies the maxstack it has computed.

    As for the nop, it's because you're compiling in debug mode. They always start a method body with a nop. See from fsharp/ilxgen.ml:

    // Add a nop to make way for the first sequence point. There is always such a 
    // sequence point even when zapFirstSeqPointToStart=false
    do if mgbuf.cenv.generateDebugSymbols  then codebuf.Add(i_nop);
    

    If I compile your factorial without debug symbols, I don't get a nop.

    0 讨论(0)
提交回复
热议问题