-
Notifications
You must be signed in to change notification settings - Fork 832
Closed
Labels
Milestone
Description
Doing a diff between structs and struct records generated code, I noticed that an extra copy is done in methods using copy and update.
Repro steps
- Create a struct type
- Create a struct record
- implement the same method that copy and update the type
- compare IL both
[<Struct>]
type Structure =
val Line: int
val OriginalLine: int
val StartOfLineAbsoluteOffset: int
new(l,ol,s) = { Line =l; OriginalLine = ol; StartOfLineAbsoluteOffset = s }
member x.NextLine =
Structure(x.Line+1, x.OriginalLine+1,x.StartOfLineAbsoluteOffset)
[<Struct>]
type Rec = {
Line: int
OriginalLine: int
StartOfLineAbsoluteOffset: int
} with
member x.NextLine =
{ x with Line = x.Line + 1; OriginalLine = x.OriginalLine+1}Expected behavior
IL should be the same
Actual behavior
There is a few extra instructions for struct records:
.maxstack 5
.locals init (valuetype Program/Rec V_0)
IL_0000: ldarg.0
IL_0001: ldobj Program/Rec
IL_0006: stloc.0
the rest is exactly similar.
Known workarounds
Use struct types.
Related information
Is this needed ? The Structure.NextLine seems ok without it.
These lines seems generated by a call to mkAddrGet function (TastOps.fs) for byref value types.
smoothdeveloper