Struct as ProvidedTypeDefinition
See original GitHub issueAt my very first attempt to create a ProvidedTypeDefinition I used the following line:
let mTy = ProvidedTypeDefinition(message.Key, baseType = Some(typeof<ValueType>),
HideObjectMethods = true, IsErased = false)
The TP and code gen worked with ValueType
until I called constructor of the provided type. Then I received a CLR error saying about stack corruption.
When I compared IL of my provided value type with a normal struct constructor I found some differences. IL_0001 calls ValueType constructor, but it shouldn’t be done for structs. It seems that it is possible to add special handling of ValueTypes on this line (and maybe somewhere else) and generate valid constructors.
I am not yet comfortable with IL. What is needed to generate structs if that is possible at all?
.method public specialname rtspecialname
instance void .ctor (
class [Spreads.Extensions]Spreads.Serialization.IDirectBuffer buffer
) cil managed
{
// Method begins at RVA 0x20d4
// Code size 31 (0x1f)
.maxstack 4
.locals init (
[0] valuetype SBETypeProviderTest.CarSchema/Car,
[1] class [Spreads.Extensions]Spreads.Serialization.IDirectBuffer
)
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.ValueType::.ctor()
IL_0006: ldarg.0
IL_0007: nop
IL_0008: nop
IL_0009: stloc.0
IL_000a: nop
IL_000b: nop
IL_000c: ldarg.1
IL_000d: nop
IL_000e: nop
IL_000f: stloc.1
IL_0010: nop
IL_0011: nop
IL_0012: ldloca.s 0
IL_0014: nop
IL_0015: nop
IL_0016: ldloc.1
IL_0017: nop
IL_0018: nop
IL_0019: stfld class [Spreads.Extensions]Spreads.Serialization.IDirectBuffer SBETypeProviderTest.CarSchema/Car::_directBuffer
IL_001e: ret
} // end of method Car::.ctor
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
typedef struct vs struct definitions [duplicate]
This answer explains how the compiler works, and using typedef is a good idea— however, it doesn't explain why the struct should be...
Read more >Struct declaration
A struct is a type consisting of a sequence of members whose storage is allocated in an ordered sequence (as opposed to union,...
Read more >Structure types - C# reference
A structure type (or struct type) is a value type that can encapsulate data and related functionality. You use the struct keyword to...
Read more >How to use the typedef struct in C
The C language contains the typedef keyword to allow users to provide alternative names for the primitive (e.g., int) and user-defined (e.g struct)...
Read more >4.1 Defining Structure Types: define-struct
struct :id, a structure type descriptor value that represents the structure type. make-id, a constructor procedure that takes m arguments and returns a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was done here: https://github.com/fsprojects/FSharp.TypeProviders.SDK/pull/344
@dsyme @tpetricek should that be feasible at all? I feel like doing this, unless there is some unknown for me blocking issue that I will learn in the process.