Generate tail call opcode

C# compiler does not give you any guarantees about tail-call optimizations because C# programs usually use loops and so they do not rely on the tail-call optimizations. So, in C#, this is simply a JIT optimization that may or may not happen (and you cannot rely on it). F# compiler is designed to handle functional … Read more

Why is it necessary to call :this() on a struct to use automatic properties in c#?

Note: as of C# 6, this isn’t required – but you should be using read-only automatically-implemented properties with C# 6 anyway… this() makes sure that the fields are definitely assigned as far as the compiler is concerned – it sets all fields to their default values. You have to have a fully constructed struct before … Read more

Call and Callvirt

When the runtime executes a call instruction it’s making a call to an exact piece of code (method). There’s no question about where it exists. Once the IL has been JITted, the resulting machine code at the call site is an unconditional jmp instruction. By contrast, the callvirt instruction is used to call virtual methods … Read more

Profiling a dynamic pinvoke

The profiler APIs are returning metadata specified in the managed code, normally via the DllImportAttribute. In the case of the ‘dynamic pinvoke’ which uses the Marshal.GetDelegateForFunctionPointer method, the module and function names were never specified as metadata and not available. An alternative approach to dynamic pinvoke declarations that includes the required metadata will probably avoid … Read more

What does beforefieldinit flag do?

See my article on this very issue. Basically, beforefieldinit means “the type can be initialized at any point before any static fields are referenced.” In theory that means it can be very lazily initialized – if you call a static method which doesn’t touch any fields, the JIT doesn’t need to initialize the type. In … Read more

What is the purpose of hidebysig in a MSIL method?

From ECMA 335, section 8.10.4 of partition 1: The CTS provides independent control over both the names that are visible from a base type (hiding) and the sharing of layout slots in the derived class (overriding). Hiding is controlled by marking a member in the derived class as either hide by name or hide by … Read more