Skip to content

Commit

Permalink
Mark attributes we codegen as CompilerGenerated (#16145)
Browse files Browse the repository at this point in the history
* Mark attributes we codegen as CompilerGenerated
  • Loading branch information
vzarytovskii authored Oct 23, 2023
1 parent 12c2a40 commit bdcedc1
Show file tree
Hide file tree
Showing 44 changed files with 70 additions and 23 deletions.
8 changes: 6 additions & 2 deletions src/Compiler/CodeGen/IlxGenSupport.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ let mkLocalPrivateAttributeWithDefaultConstructor (g: TcGlobals, name: string) =
g.AddMethodGeneratedAttributes(mkILNonGenericEmptyCtor (g.ilg.typ_Attribute, None, None))
]

let ilCustomAttrs = mkILCustomAttrsFromArray [| g.CompilerGeneratedAttribute |]

mkILGenericClass (
name,
ILTypeDefAccess.Private,
Expand All @@ -49,7 +51,7 @@ let mkLocalPrivateAttributeWithDefaultConstructor (g: TcGlobals, name: string) =
emptyILTypeDefs,
emptyILProperties,
emptyILEvents,
emptyILCustomAttrs,
ilCustomAttrs,
ILTypeInit.BeforeField
)

Expand Down Expand Up @@ -104,6 +106,8 @@ let mkLocalPrivateAttributeWithPropertyConstructors (g: TcGlobals, name: string,
)
)

let ilCustomAttrs = mkILCustomAttrsFromArray [| g.CompilerGeneratedAttribute |]

mkILGenericClass (
name,
ILTypeDefAccess.Private,
Expand All @@ -118,7 +122,7 @@ let mkLocalPrivateAttributeWithPropertyConstructors (g: TcGlobals, name: string,
emptyILTypeDefs,
mkILProperties (ilElements |> List.map (fun (_, _, property, _) -> property)),
emptyILEvents,
emptyILCustomAttrs,
ilCustomAttrs,
ILTypeInit.BeforeField
)

Expand Down
43 changes: 22 additions & 21 deletions tests/FSharp.Compiler.ComponentTests/EmittedIL/ByRefTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ type C() =
let verifyProperty = """.property instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
X()
{
.custom instance void [runtime]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.get instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute) Test/C::get_X()
}"""

let verifyMethod = """.method public hidebysig specialname
instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
let verifyMethod = """.method public hidebysig specialname
instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
get_X() cil managed
{
.param [0]
Expand All @@ -309,12 +309,12 @@ type C() =
let verifyProperty = """.property instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
X()
{
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.get instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute) Test/C::get_X()
}"""

let verifyMethod = """.method public hidebysig specialname
instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
let verifyMethod = """.method public hidebysig specialname
instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
get_X() cil managed
{
.param [0]
Expand All @@ -324,11 +324,12 @@ type C() =
.class private auto ansi beforefieldinit System.Runtime.CompilerServices.IsReadOnlyAttribute
extends [System.Runtime]System.Attribute
{
.method public specialname rtspecialname
.custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public specialname rtspecialname
instance void .ctor() cil managed
{
.custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [netstandard]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [netstandard]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
Expand Down Expand Up @@ -361,7 +362,7 @@ type C() =
let verifyProperty = """.property instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
X()
{
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.get instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute) System.Runtime.CompilerServices.C::get_X()
}"""

Expand All @@ -375,18 +376,18 @@ type C() =
.class public auto ansi serializable System.Runtime.CompilerServices.IsReadOnlyAttribute
extends [netstandard]System.Attribute
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 )
.method public specialname rtspecialname
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 )
.method public specialname rtspecialname
instance void .ctor() cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: callvirt instance void [netstandard]System.Attribute::.ctor()
IL_0006: ldarg.0
IL_0007: pop
IL_0008: ret
}
}
}"""

Expand All @@ -407,7 +408,7 @@ type C<'T>() =
member _.X<'U>(): inref<'T> = &x
"""

let verifyMethod = """.method public hidebysig instance !T& modreq([runtime]System.Runtime.InteropServices.InAttribute)
let verifyMethod = """.method public hidebysig instance !T& modreq([runtime]System.Runtime.InteropServices.InAttribute)
X<U>() cil managed
{
.param [0]
Expand All @@ -434,7 +435,7 @@ module Test =
member _.X<'U>(): inref<'T> = &x
"""

let verifyMethod = """.method public hidebysig instance !T& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
let verifyMethod = """.method public hidebysig instance !T& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
X<U>() cil managed
{
.param [0]
Expand All @@ -457,8 +458,8 @@ type C<'T>() =
abstract X<'U> : unit -> inref<'U>
"""

let verifyMethod = """.method public hidebysig abstract virtual
instance !!U& modreq([runtime]System.Runtime.InteropServices.InAttribute)
let verifyMethod = """.method public hidebysig abstract virtual
instance !!U& modreq([runtime]System.Runtime.InteropServices.InAttribute)
X<U>() cil managed
{
.param [0]
Expand All @@ -476,18 +477,18 @@ type C<'T>() =
module Test
type C =
abstract X: inref<int>
abstract X: inref<int>
"""

let verifyProperty = """.property instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
X()
{
.custom instance void [runtime]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.get instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute) Test/C::get_X()
}"""

let verifyMethod = """.method public hidebysig specialname abstract virtual
instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
get_X() cil managed
{
.param [0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@
.class private auto ansi beforefieldinit System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
extends [runtime]System.Attribute
{
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes MemberType@
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
Expand Down
Loading

0 comments on commit bdcedc1

Please sign in to comment.