Tuesday, September 15, 2009

F# under the covers III

To date we've seen examples where some simple F# code maps to something horrid in the C# view we get from Reflector.

Now for something completely different...

Simple properties like

map quite directly from F# into IL, even in debug build

where set_Points just assigns straight into the field, and get_Points just returns it, roughly as expected.

The corresponding C#


The set_Points code is the same, modulo the maxstack -- but what are that temporary and that branch doing in get_Points?

This is a bit of a "lolwut!?" discovery!

Reassuringly, the release build of the C# get_Points is almost a nop-free version of the F# debug code

but as the debug version is the one for doing code analysis on, that's less useful.

This is unchanged with the Feb 2010 CTP (

1 comment :

Yann Schwartz said...

The added IL instructions are meant to better support debugging (the jump makes it easier to set breakpoints, and the temp local makes it possible to add a watch on the value and change it).

There's a lot of fluff added to a C# debug build to support these kind of scenarios. Not so much in F#, it seems.