dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.86k stars 779 forks source link

[Question] Instrumenting inline functions for code coverage #12263

Open daveMueller opened 2 years ago

daveMueller commented 2 years ago

Hi,

I'm working on a code coverage tool and we are facing issues when calculating coverage for inline functions. We instrument the code on IL level and the inline function calls are also instrumented in that way.

The function calls are instrumented properly but due to the fact that the compiler inlines the function body instead of calling the function, the code is never hit by our coverage tool (because the function is never called).

What we would need is a mapping of the functions sequence points to the location where the function body is inlined. Thus we could add our intrumentation / tracker to the right location in the assemblies IL.

Any idea how we could do this?

(this is the corresponding issue in our repo: https://github.com/coverlet-coverage/coverlet/issues/1225)

dsyme commented 2 years ago

This is tricky. We looked at maintaining the ranges for inline functions in https://github.com/dotnet/fsharp/pull/11717, but then reverted it in https://github.com/dotnet/fsharp/pull/11792. Getting good debugging of functional code (any code that uses delayed execution) is a tricky problem.

We could in theory emit bespoke mapping information but we don't do anything like that at the moment.

daveMueller commented 2 years ago

OK thanks. I just wanted to close this ticket but I've seen you changed the label to feature request. We more often have fsharp programmer using coverlet so I think this would help us to also make their coverage more accurate.