Skip to content
Closed
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.100.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Fixed

* Fix `StructLayout` `Size` for struct discriminated unions so emitted IL matches the computed layout size. ([Issue #18125](https://github.com/dotnet/fsharp/issues/18125), [PR #19946](https://github.com/dotnet/fsharp/pull/19946))
* Fix internal error (FS0193) when calling an indexed property setter with a named argument that matches an indexer parameter. ([Issue #16034](https://github.com/dotnet/fsharp/issues/16034), [PR #19851](https://github.com/dotnet/fsharp/pull/19851))
* Fix missing FS1182 ("unused binding") warning for unused `let` function bindings inside class types. ([Issue #13849](https://github.com/dotnet/fsharp/issues/13849), [PR #19805](https://github.com/dotnet/fsharp/pull/19805))
* Fix inner mutually-recursive `let rec ... and ...` functions under `--realsig+` not being lifted to top-level static methods (TLR), causing `FSharpFunc` closure allocations and loss of `tail.` opcodes — the large struct-mutual-recursion perf regression reported in [Issue #17607](https://github.com/dotnet/fsharp/issues/17607). ([PR #19882](https://github.com/dotnet/fsharp/pull/19882))
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12019,6 +12019,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) : ILTypeRef option
// Structs with no instance fields get size 1, pack 0
if
tycon.AllFieldsArray |> Array.exists (fun f -> not f.IsStatic)
|| tycon.IsUnionTycon

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code path is for objects and records, union IL codegen happens elsewhere.
I am going to close this PR and continue at #19759 , but please do come over and share feedback there, I am happy to improve it even further 👍 .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it looks like you were already working there on the same issue. I just posted comment there.

||
// Reflection emit doesn't let us emit 'pack' and 'size' for generic structs.
// In that case we generate a dummy field instead
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Regression test for https://github.com/dotnet/fsharp/issues/18125
module StructUnionLayout18125

[<Struct>]
type ABC = A | B | C

let verifySize () =
// Struct DU has a compiler-generated _tag field; sizeof must not be 1.
if sizeof<ABC> <> 4 then
failwith $"Expected sizeof<ABC> = 4, got {sizeof<ABC>}"

verifySize ()
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,10 @@ module Structure =
compilation
|> getCompilation
|> verifyExecution

// SOURCE=StructUnionLayout18125.fs SCFLAGS="-r:CodeGenHelper.dll" # StructUnionLayout18125.fs
[<Theory; FileInlineData("StructUnionLayout18125.fs")>]
let ``StructUnionLayout18125_fs`` compilation =
compilation
|> getCompilation
|> verifyExecution
Loading