Skip to content

Commit 7355966

Browse files
authored
IlxGen: fix missing CompilationMapping attribute for generic values (#19643)
* IlxGen: fix missing CompilationMapping attribute for generic values * Release notes * Update baselines
1 parent 2187bab commit 7355966

7 files changed

Lines changed: 37 additions & 5 deletions

File tree

docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* Fix signature generation: `private` keyword placement for prefix-style type abbreviations. ([Issue #15560](https://github.com/dotnet/fsharp/issues/15560), [PR #19586](https://github.com/dotnet/fsharp/pull/19586))
3636
* Fix signature generation: missing `[<Class>]` attribute for types without visible constructors. ([Issue #16531](https://github.com/dotnet/fsharp/issues/16531), [PR #19586](https://github.com/dotnet/fsharp/pull/19586))
3737
* Fix methods being tagged as `Member` instead of `Method` in tooltips. ([Issue #10540](https://github.com/dotnet/fsharp/issues/10540), [PR #19507](https://github.com/dotnet/fsharp/pull/19507))
38+
* IlxGen: fix missing CompilationMapping attribute for generic values ([PR #19643](https://github.com/dotnet/fsharp/pull/19643))
3839

3940
### Added
4041

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9863,8 +9863,14 @@ and GenMethodForBinding
98639863
| _ -> ilAttrsThatGoOnPrimaryItem
98649864
| _ -> ilAttrsThatGoOnPrimaryItem
98659865

9866+
let compilationMappingAttrs =
9867+
[
9868+
if v.MemberInfo.IsNone && curriedArgInfos.IsEmpty then
9869+
mkCompilationMappingAttr g (int SourceConstructFlags.Value)
9870+
]
9871+
98669872
let ilCustomAttrs =
9867-
mkILCustomAttrs (ilAttrs @ sourceNameAttribs @ ilAttrsCompilerGenerated)
9873+
mkILCustomAttrs (ilAttrs @ compilationMappingAttrs @ sourceNameAttribs @ ilAttrsCompilerGenerated)
98689874

98699875
let mdef = mdef.With(customAttrs = ilCustomAttrs)
98709876
mdef

tests/FSharp.Compiler.ComponentTests/EmittedIL/CodeGenRegressions/CodeGenRegressions_Observations.fs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,28 @@ type MyClass() =
193193
|> shouldSucceed
194194
|> verifyAssemblyReference "System.Xml"
195195
|> ignore
196+
197+
198+
// https://github.com/dotnet/fsharp/issues/19428
199+
[<Fact>]
200+
let ``Issue_19428_CompilationMappingOnGenericValue`` () =
201+
FSharp """
202+
module GenericValueTest
203+
204+
let l = []
205+
let empty<'T> = Seq.empty<'T>
206+
"""
207+
|> compile
208+
|> shouldSucceed
209+
|> verifyIL [
210+
"""
211+
.method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!!a> l<a>() cil managed
212+
{
213+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
214+
"""
215+
"""
216+
.method public static class [runtime]System.Collections.Generic.IEnumerable`1<!!T> empty<T>() cil managed
217+
{
218+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
219+
"""
220+
]

tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction09b4.fs.RealInternalSignatureOff.OptimizeOff.il.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
.method public static !!a Null<class a>() cil managed
3737
{
3838
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.LiteralAttribute::.ctor() = ( 01 00 00 00 )
39+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
3940

4041
.maxstack 3
4142
.locals init (!!a V_0)
@@ -99,4 +100,3 @@
99100

100101

101102

102-

tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction09b4.fs.RealInternalSignatureOff.OptimizeOn.il.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
.method public static !!a Null<class a>() cil managed
4242
{
4343
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.LiteralAttribute::.ctor() = ( 01 00 00 00 )
44+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
4445

4546
.maxstack 3
4647
.locals init (!!a V_0)
@@ -107,4 +108,3 @@
107108

108109

109110

110-

tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction09b4.fs.RealInternalSignatureOn.OptimizeOff.il.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
.method public static !!a Null<class a>() cil managed
3737
{
3838
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.LiteralAttribute::.ctor() = ( 01 00 00 00 )
39+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
3940

4041
.maxstack 3
4142
.locals init (!!a V_0)
@@ -116,4 +117,3 @@
116117

117118

118119

119-

tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction09b4.fs.RealInternalSignatureOn.OptimizeOn.il.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
.method public static !!a Null<class a>() cil managed
4242
{
4343
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.LiteralAttribute::.ctor() = ( 01 00 00 00 )
44+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
4445

4546
.maxstack 3
4647
.locals init (!!a V_0)
@@ -126,4 +127,3 @@
126127

127128

128129

129-

0 commit comments

Comments
 (0)