Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12031,15 +12031,9 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) : ILTypeRef option
}

let layout =
// Structs with no instance fields get size 1, pack 0
// Struct unions always carry a hidden tag field, so never emit size 1 here
if isStructTy g thisTy then
if
(tycon.AllFieldsArray.Length = 0
|| tycon.AllFieldsArray |> Array.exists (fun f -> not f.IsStatic))
&& (alternatives
|> Array.collect (fun a -> a.FieldDefs)
|> Array.exists (fun fd -> not fd.ILField.IsStatic))
then
if tycon.IsUnionTycon then
ILTypeDefLayout.Sequential { Size = None; Pack = None }
else
ILTypeDefLayout.Sequential { Size = Some 1; Pack = Some 0us }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ module CustomAttributes_Basic =
]

[<Fact>]
let ``StructLayoutAttribute has size=1 for struct DUs with no instance fields`` () =
let ``StructLayoutAttribute doesn't have size=1 for struct DUs with no instance fields`` () =
Fsx """
[<Struct>] type Option<'T> = None | Some
"""
Expand All @@ -413,8 +413,6 @@ module CustomAttributes_Basic =
[runtime]System.IComparable,
[runtime]System.Collections.IStructuralComparable
{
.pack 0
.size 1
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string) = ( 01 00 15 7B 5F 5F 44 65 62 75 67 44 69 73 70 6C
61 79 28 29 2C 6E 71 7D 00 00 )
Expand All @@ -426,4 +424,4 @@ module CustomAttributes_Basic =
.field public static literal int32 Some = int32(0x00000001)
}
"""
]
]
Loading