Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/baronfel/ilverify-fsharp-error-demo


https://github.com/baronfel/ilverify-fsharp-error-demo

Last synced: 9 days ago
JSON representation

Awesome Lists containing this project

README

        

# ILVerify test harness for c#/f# code difference

The ilverify tool doesn't like the IL generated by the F# compiler for this function call, but it is fine with that of the C# compiler.

This repo exists to demonstrate the problem and see what the solution is.

## Test C\#

cd to `ilver` and run `dotnet build`, then run `ilverify bin/Debug//ilver.dll -r /*.dll`

You'll get something like

```
> ilverify bin/Debug/net5.0/ilver.dll -r /usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.0-preview.6.20305.6/*.dll -t --statistics
All Classes and Methods in /Users/chethusk/scratch/ilverify-check/ilver/bin/Debug/net5.0/ilver.dll Verified.
Types found: 2
Types verified: 2
Methods found: 2
Methods verified: 2
```

## Test F\#

cd to `ilverfs` and run `dotnet build`, then run `ilverify bin/Debug//ilverfs.dll -r /*.dll`

You'll get something like

```
> ilverify bin/Debug/net5.0/ilverfs.dll -r /usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.0-preview.6.20305.6/*.dll -t --statistics
[IL]: Error [StackUnexpected]: [/Users/chethusk/scratch/ilverify-check/ilverfs/bin/Debug/net5.0/ilverfs.dll : .ilverfs::relative(string)][offset 0x0000000B][found Char] Unexpected type on the stack.
1 Error(s) Verifying /Users/chethusk/scratch/ilverify-check/ilverfs/bin/Debug/net5.0/ilverfs.dll
Types found: 5
Types verified: 5
Methods found: 1
Methods verified: 1
```

## IL generated for C\#

(taken from [sharplab](https://sharplab.io/#v2:C4LglgNgNAJiDUAfAAgJgIwFgBQyDMABGgQMIEDeOB1Rhy6AbAQMrABOYAdgOYFsCmEAIbAwAN34EAFKw48CAZ37cAtv07AAlBSo09yAOyLlajQDoAKhxWshbYFM78A7gG0AuuQDkAei8BfTQBuXWp/HH8gA)):

```il
// Methods
.method public hidebysig static
string relative (
string segment
) cil managed
{
// Method begins at RVA 0x2050
// Code size 23 (0x17)
.maxstack 5
.locals init (
[0] string
)

IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldc.i4.1
IL_0003: newarr [System.Private.CoreLib]System.Char
IL_0008: dup
IL_0009: ldc.i4.0
IL_000a: ldc.i4.s 47
IL_000c: stelem.i2
IL_000d: callvirt instance string [System.Private.CoreLib]System.String::TrimStart(char[])
IL_0012: stloc.0
IL_0013: br.s IL_0015

IL_0015: ldloc.0
IL_0016: ret
}
```

## IL generated for F\#

(taken from [sharplab](https://sharplab.io/#v2:DYLgZgzgNALiCWwoBMQGoA+ACLwCmMWATnsAIYzwBueWAFBHgOYC2eAdoSFhDEfOyYBKLAF4AsACgcMnszacAdABV+LAMowyRQgG1sAcgD0BrBgC6QA=))

```il
.method public static
class [System.Private.CoreLib]System.String relative (
class [System.Private.CoreLib]System.String segment
) cil managed
{
// Method begins at RVA 0x2050
// Code size 22 (0x16)
.maxstack 8

IL_0000: ldarg.0
IL_0001: ldc.i4.1
IL_0002: newarr [System.Private.CoreLib]System.Char
IL_0007: dup
IL_0008: ldc.i4.0
IL_0009: ldc.i4.s 47
IL_000b: stelem [System.Private.CoreLib]System.Char
IL_0010: callvirt instance string [System.Private.CoreLib]System.String::TrimStart(char[])
IL_0015: ret
}
```