Auto-generated getters on structs get readonly attribute#13413
Merged
0101 merged 14 commits intodotnet:mainfrom Jul 8, 2022
Merged
Auto-generated getters on structs get readonly attribute#134130101 merged 14 commits intodotnet:mainfrom
0101 merged 14 commits intodotnet:mainfrom
Conversation
b9484c2 to
41035ab
Compare
a19aa4a to
738184c
Compare
… struct-getters-readonly
psfinaki
reviewed
Jul 5, 2022
psfinaki
reviewed
Jul 5, 2022
src/Compiler/CodeGen/IlxGen.fs
Outdated
| let ilMethName = "get_" + ilPropName | ||
| let access = ComputeMemberAccess isPropHidden | ||
| yield mkLdfldMethodDef (ilMethName, access, isStatic, ilThisTy, ilFieldName, ilPropType) | ||
| let isStruct = tcref.IsFSharpStructOrEnumTycon && not tcref.IsEnumTycon |
Contributor
There was a problem hiding this comment.
Just curious, why the check is implemented this way?
At least in the IL code something else seems to be analyzed.
Contributor
Author
There was a problem hiding this comment.
Seemed like the easiest way to do it here. I'm definitely open to other suggestions. Maybe we should add IsFShartStructTycon. Or maybe just use IsFSharpStructOrEnumTycon because enum will never reach this place.
Contributor
There was a problem hiding this comment.
Leaving it up to you, just voting for consistent approach if applicable
Contributor
Author
There was a problem hiding this comment.
I don't think we can do it like in ILTypeDef, but I did find another way which might be better.
Contributor
There was a problem hiding this comment.
Anyway, I'm definitely okay with the current approach
psfinaki
reviewed
Jul 5, 2022
psfinaki
reviewed
Jul 5, 2022
tests/FSharp.Compiler.ComponentTests/EmittedIL/StructGettersReadOnly.fs
Outdated
Show resolved
Hide resolved
vzarytovskii
approved these changes
Jul 7, 2022
psfinaki
reviewed
Jul 7, 2022
psfinaki
approved these changes
Jul 7, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#8962
So far it works for records and anonymous records.
Would like to get it to work for regular structs too but they seem to use a different mechanism for generating their getters.The following case is not covered, because that would require analyzing user supplied getter code for side-effects.
It does work for when the getter is auto-generated: