-
Notifications
You must be signed in to change notification settings - Fork 833
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
Open
DragonSA
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
DragonSA:fix-returnattr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−39
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9360,6 +9360,14 @@ and GenMethodForBinding | |
| g.DebuggerNonUserCodeAttribute | ||
| ] | ||
|
|
||
| // Remove attributes that are applied to the return. These attributes need to be passed through ValRef.Attribs so that | ||
| // ActivePatternElemsOfValRef will correctly propagate `[<return: Struct>]` on active patterns. | ||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. Instead of filtering, one could partition and move the return attributes into This would be the smaller change, but I feel it would continue the mis-propagation of attributes... |
||
| let ilAttrsThatGoOnPrimaryItem = | ||
| [ | ||
| yield! GenAttrs cenv eenv attrs | ||
|
|
||
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
5 changes: 5 additions & 0 deletions
5
tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ReturnAttributeOnClassMethod.fs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| open System.Diagnostics.CodeAnalysis | ||
|
|
||
| type Class() = | ||
| [<return: NotNull>] | ||
| static member ClassMethod () = obj() |
81 changes: 81 additions & 0 deletions
81
tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ReturnAttributeOnClassMethod.fs.il.bsl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| .assembly extern runtime { } | ||
| .assembly extern FSharp.Core { } | ||
| .assembly assembly | ||
| { | ||
| .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, | ||
| int32, | ||
| int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| .hash algorithm 0x00008004 | ||
| .ver 0:0:0:0 | ||
| } | ||
| .module assembly.exe | ||
|
|
||
| .imagebase {value} | ||
| .file alignment 0x00000200 | ||
| .stackreserve 0x00100000 | ||
| .subsystem 0x0003 | ||
| .corflags 0x00000001 | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| .class public abstract auto ansi sealed assembly | ||
| extends [runtime]System.Object | ||
| { | ||
| .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) | ||
| .class auto ansi serializable nested public Class | ||
| extends [runtime]System.Object | ||
| { | ||
| .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 [runtime]System.Object::.ctor() | ||
| IL_0006: ldarg.0 | ||
| IL_0007: pop | ||
| IL_0008: ret | ||
| } | ||
|
|
||
| .method public static object ClassMethod() cil managed | ||
| { | ||
| .param [0] | ||
| .custom instance void [runtime]System.Diagnostics.CodeAnalysis.NotNullAttribute::.ctor() = ( 01 00 00 00 ) | ||
|
|
||
| .maxstack 8 | ||
| IL_0000: newobj instance void [runtime]System.Object::.ctor() | ||
| IL_0005: ret | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| .class private abstract auto ansi sealed '<StartupCode$assembly>'.$assembly | ||
| extends [runtime]System.Object | ||
| { | ||
| .method public static void main@() cil managed | ||
| { | ||
| .entrypoint | ||
|
|
||
| .maxstack 8 | ||
| IL_0000: ret | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
Oops, something went wrong.
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.
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.