views:

153

answers:

3

When I am reading F# stuff, they are talking about inlining methods, but I thought .NET didn't expose this functionality to programmers. If it's exposed then it has to be in the IL? And so can C# make use of it as well?

Just wondering if this thing is the same as C++ inline functionality.

+4  A: 

Guess I'll post as an answer... didn't really want to do such because I don't know anything about F# beyond the basics. :p

http://msdn.microsoft.com/en-us/library/dd548047%28VS.100%29.aspx

Tanzelax
Thanks Tanzelax.
Joan Venge
+3  A: 

To answer some of your specific questions, inline is an F#-specific construct that interacts with both the type system (e.g. static member constraints) and code generation (inlining code for optimization purposes). The F# compiler deals with these things, and the information regarding inlining is stored in F#-specific metadata in the assembly, which enables functions to be inlined across F# assembly boundaries.

Brian
+2  A: 

It is actually more complicated when compared to C++ inlining, because F# works on top of .NET, which has IL as an intermediate language, so there are actually two layers where some inlining can be done:

  • At the F# -> IL level - The inline keyword allows you to specify that an F# function should be inlined when generating .NET IL code. In this case, the IL instructions of the function will be placed in place of a IL instruction representing a method call.

  • At the IL -> assembly level - This is fully controlled by JITter (.NET just-in-time compiler), which compiles the IL (intermediate language) to actual executable assembly code. This is done fully automatically, so you cannot specify that something should be inlined at this level. However, JITter also inlines some simple calls (such as calls to property getters and setters).

Tomas Petricek