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

"System.Func overload-is-better": checking if anything breaks, or not (in which case, we'd like a test) #11538

Conversation

smoothdeveloper
Copy link
Contributor

Related to #11534 and prompted by excellent suggestion from @baronfel to apply the warning wave protocol (as was done with XML docs warnings) to tackle issues around "System.Func overload is better".

This PR is, for now, just checking if we have tests that would fail due to this feature of the compiler, and potentially adding one if not.

@smoothdeveloper
Copy link
Contributor Author

smoothdeveloper commented May 9, 2021

Mmh, unless I miss something, this being green may indicate we basically have a hole in the tests in terms of asserting overloading with func-is-better holds.

The thing I could be missing is that all the tests are run with --compiling-fslib stuff, which I doubt is the case.

@smoothdeveloper
Copy link
Contributor Author

So, it seems in F# compiler codebase and tests, beside the test I've added in this PR, there is nothing which checks for "func-is-better".

This doesn't make me super confident in the test suite having nearly enough checks on the nitty gritty of overload resolution.

I'll try to hack a bit on having the warning, if that proves simple enough, it could turn this PR into fixing #11534 and prepare the ground for removing the support for "func-is-better" in a later major version.

@dsyme, would you mind sharing a bit here or in #11534 some of the historical reasons for "func-is-better" in overload resolution? and if you are favorable with a warning wave and eventual deprecation of that special casing?

On my end, for sake of explicitness and principle of least surprise, treating all delegate types the same, I'd favor taking this out in next major release (could even do this under preview guards soon), and later, work on addressing issues such as highlighted in #2503 (comment).

@smoothdeveloper
Copy link
Contributor Author

This is green and ready for a first round of review.

@@ -508,6 +508,29 @@ type CalledMeth<'T>
/// The argument analysis for each set of curried arguments
member x.ArgSets = argSets

member x.GetCallerArgAt index =
// Arrays are better...
let mutable currentIndex = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be looking at reimplementing this in terms of List.mapi2, this has been first try to make things work (it passes the test, but the test likely doesn't covers all possible cases).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is problematic, I wrote it before surveying some more my assumptions (in #11544, which shows that my assumptions are just wrong).

Looking for guidance on how we want that to work to get this PR considered for merge.

Also eager to hear if there is a point or no, to move from list list representation of SynValInfo, I know @baronfel was facing slightly related question recently:

anyone have any insight into why a named tuple-parameter is erased in the TAST? eg
let myFun (f: (int * int * int)) = ()
in the TAST is represented as an FSharpMemberOrFunctionOrValue, whose CurriedParameterArgs is a list< list< FSharpParameter > > of length 1, whose inner list is of length 3. The three inner parameters are unnamed, but as a result of this form I lose information (as an IDE user) about the name/documentation of the parameter.

which shows that the representation as we have it, from the parser AST down to the typed AST is a bit arcane to the people not used to it.

@@ -0,0 +1,16 @@

neg_at_somepoint_in_the_future_func-is-better-or-not.fsx(14,1,14,17): typecheck error FS0193: The method 'M' has overload with 'System.Func' delegate in the signature, to fix the warning, you need to specify the type explicitly.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrt to the warning message itself:

  • there may be potential to show the CallerArg.Expr expression, if there are existing facilities to prettify it
  • it might be worth to mention which argument (by the name of it from CalledArg) is causing the warning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying the argument name may be problematic in circumstances similar to what @baronfel was dealing with, patterns and "anonymous" parameters.

If there are places we already prettify Expr to display to the end user, please let me know and I'll try to experiment with it.

Probably several error messages could benefit from having this kind of "expanding the expression to explain the error in actual case".

@Happypig375
Copy link
Member

Bump @cartermp

@dsyme
Copy link
Contributor

dsyme commented Jun 29, 2021

@smoothdeveloper Could you include the XLF file updates as well please (see DEVGUIDE.md)

@TIHan
Copy link
Contributor

TIHan commented Oct 25, 2021

There are merge conflicts and test failures that needs to be resolved.

@vzarytovskii vzarytovskii marked this pull request as draft December 8, 2022 12:09
@KevinRansom
Copy link
Member

@smoothdeveloper
Thanks for proposing this contribution, however, it seems to have gotten a little stale. Tests fail, there are conflicts, the last comment was fifteen months ago.

Please feel free to re-open if you wish to continue to work on this PR.

Kevin

@smoothdeveloper
Copy link
Contributor Author

@KevinRansom, no issue, we could scope it for #15901, I think the implementation for it didn't give me too much trouble, so I could give it on top of the then-to-be-current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants