The code coverage tool in Visual studio 2012 marks all inline
functions as uncovered even when they were covered.
Is there any way how to make code coverage work for inline
functions?
f = inline( expr , arg1,arg2,…,argN ) constructs an inline function whose input arguments are specified by arg1,arg2,…,argN . Multicharacter symbol names may be used. f = inline( expr , N ) , where N is a scalar, constructs an inline function whose input arguments are x and P1,P2,…,PN .
Example. In the following class declaration, the Account constructor is an inline function. The member functions GetBalance , Deposit , and Withdraw aren't specified as inline but can be implemented as inline functions. In the class declaration, the functions were declared without the inline keyword.
Inline functions are expanded by the compiler. Macros are expanded by the preprocessor. They are defined by the keyword inline. They are defined by the keyword #define.
An inline C# function is a CMS function written in C# and normally created in the CMS Console (unlike external C# functions, created in external editors and added to C1 CMS). To create an inline C# function: In Functions, select C# Functions and click Add InlineC# Function.
When you write an inline
function, the compiler inlines the body of the function into the calling code. As discussed in the comments, it also does not emit debug information for this inlined body (and so you cannot step into the function - I think this could be fixed - submit a request to fsbugs
at microsoft
dot com
).
However, the compiler also generates a dynamic version of the code - if you write say:
let inline add a b = a + b
then there is actually an add
method in the compiled code. The method will be generic ('a -> 'b -> 'c
) and uses dynamic lookup to find an appropriate implementation of the +
operator (because .NET generics cannot represent such constraints).
The dynamic implementation will be invoked when you use reflection or quotations:
open Microsoft.FSharp.Linq.RuntimeHelpers
<@ add 1 2 @> |> LeafExpressionConverter.EvaluateQuotation |> printfn "Got: %A"
If you put breakpoint inside add
and run the above code than the breakpoint will be hit (and I assume the code coverage tool will report the function as covered).
But keep in mind that this is not the code that is actually executed when you write add 1 2
in normal code - the code executing here is a different implementation (that uses slow dynamic lookup, rather than inlining).
Aren't inline functions directly integrated into the calling code? If so no actual method is called as the code is 'inlined' and for each place they are used a new copy of the inlined code exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With