Respect the return qualifier for attributes on class methods#19025
Respect the return qualifier for attributes on class methods#19025DragonSA wants to merge 7 commits intodotnet:mainfrom
Conversation
❗ Release notes required
|
30f5af1 to
41a384b
Compare
There was a problem hiding this comment.
Please minimise the diff. So it is easier to review.
There was a problem hiding this comment.
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.
Thanks. To fix the formatting we need to restore the dotnet tools and run dotnet fantomas .
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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.
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?
| if List.length attribs <> attrs.Length then [], [], attribs | ||
| else attribs | ||
| |> List.zip attrs | ||
| |> List.partition(function | _, Attrib(_, _, _, _, _, Some ts, _) -> ts &&& AttributeTargets.ReturnValue <> enum 0 | _ -> false) |
There was a problem hiding this comment.
The added check here does not make sense, since the line at TcAttrs below would be the one for checking attribute targets and report appropriately, it is why it is there.
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