-
Notifications
You must be signed in to change notification settings - Fork 830
Respect the return qualifier for attributes on class methods #19025
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
base: main
Are you sure you want to change the base?
Conversation
❗ Release notes required
|
30f5af1 to
41a384b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please minimise the diff. So it is easier to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the white-space churn and also fixed a bug this introduced that caused recursive active pattern matches that return struct to fail (see test Rec struct active pattern is possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. To fix the formatting we need to restore the dotnet tools and run dotnet fantomas .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed the formatting fix. I see the AOT test is failing due to a size change. I cannot run the AOT test on my mac, so I haven't updated the expected values. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normally just update the expected values and wait for the review. I think the value diff reduction is related the removal of the attributes in IlxGen.fs. Maybe @vzarytovskii can give some more insight here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, majority of codegen changes will result in size change for AOT, size check is there on purpose, so we are conscious about these sorts of changes. If it's expected, just update the size.
41a384b to
cfb0589
Compare
| let attrs = | ||
| attrs | ||
| |> List.filter (function Attrib(targetsOpt = Some flags) -> not (flags.HasFlag(AttributeTargets.ReturnValue)) | _ -> true) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of filtering, one could partition and move the return attributes into ilReturn below. Then, all the changes to CheckExpressions.fs would not be required.
This would be the smaller change, but I feel it would continue the mis-propagation of attributes...
| let retAttribs = | ||
| match rtyOpt with | ||
| | Some (SynBindingReturnInfo(attributes = Attributes retAttrs)) -> | ||
| rotRetAttribs @ TcAttrs cenv env attrTgt AttributeTargets.ReturnValue true retAttrs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this mean that the return attributes will be TcAttrs'd twice, leading to type checking and diagnostics duplicates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this to fix active pattern tests that broke when the return attribute was rotated out. As far as a I recall correctly, this was caused by ActivePatternElemsOfValRef using the ValRef, instead of using the return attributes. I was not able to find an easy way to fix this.
To check, I've now created an attribute only applicable to properties and added it as a return attribute on a method. It returned two error messages, as you suspected.
A trivial alternative to this is the alternative change I suggested to src/Compiler/CodeGen/IlxGen.fs. I do feel that is an outright hack. But, based on guidance here I am happy to submit an alternative PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking is the right place, we want the attributes also to be checked for their attribute targets (e.g. an attribute only configured for the ReturnValue target such be type checked properly), ilxgen would indeed be a hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO you should first separate the attributes (return value vs rest), and then TcAttrs each group separately, with the different AttributeTargets.
Does that make sense, would it work?
Description
Attributes attached to the return value of a class method (e.g.
[<return: NotNull>]) were instead being attached to the method itself. This did not happen for functions (let bind). I refactored the logic out ofTcNormalizedBinding(used byTcLetBindingand used that inAnalyzeAndMakeAndPublishRecursiveValue.Fixes #19020
Checklist
Sponsored by CP Dynamics