Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorate automatically implemented properties with CompilerGenerated attribute #736

Open
AdhemarVandamme opened this issue Apr 26, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@AdhemarVandamme
Copy link

commented Apr 26, 2019

Decorate automatically implemented properties with CompilerGenerated attribute

The C# en F# compiler differ in their CIL bytecode ouput of automatically implemented properties.

First, the C# compiler uses a backing field ClassName::'<PropertyName>k__BackingField' whereas the F# compiler uses a backing field ClassName::PropertyName@. That’s not the problem.

Second, and this is what this feature request is about: the C# decorates both the get and the set methods of automatically implemented properties with a System.Runtime.CompilerServices.CompilerGeneratedAttribute.

This means both
.method public hidebysig specialname instance PropertyType get_PropertyName() cil managed
and
.method public hidebysig specialname instance void set_PropertyName(PropertyType 'value') cil managed
start off with
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )

Currently, the F# compiler doesn’t.

I propose that the F# compiler also decorates both the get and the set methods of automatically implemented properties with a CompilerGeneratedAttribute.

Pros and Cons

The advantage of making this adjustment to the F# compiler is to make the F# compiler behave like the C# compiler in this regard.

Realm (.NET) is a project where the appearance of a CompilerGeneratedAttribute (at least on the get method) makes a difference. Without the attribute, Realm doesn’t really work on F# types, even if their properties are automatically implemented. There’s an open issue on Realm (.NET) to work around this , but arguably the cleaner fix is to make the F# compiler behave like the C# compiler in this regard.

The only disadvantage of making this adjustment to the F# compiler that I can think of, is that the CIL output is a few bytes larger.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

This is not even a change to the F# language design; but a change to the F# compiler.

@realvictorprm

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

Correct me if I'm wrong but if I remember correctly this is actually a bug and should already be the case

@AdhemarVandamme

This comment has been minimized.

Copy link
Author

commented Apr 26, 2019

@realvictorprm I suppose this issue could be considered a bug (in the compiler) rather than a feature suggestion/request. Does this mean I should report this someplace else?

@voronoipotato

This comment has been minimized.

Copy link

commented May 8, 2019

🤷‍♂

@realvictorprm

This comment has been minimized.

Copy link
Member

commented May 8, 2019

cc @dsyme. Simple to answer this question from your point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.