Skip to content

Conversation

@panesofglass
Copy link
Contributor

@panesofglass panesofglass commented Jun 6, 2020

This is an update to #4949

Implementation for fsharp/fslang-suggestions#69.
RFC here
tests in progress.

cc @KevinRansom and @Nhowka

@dnfadmin
Copy link

dnfadmin commented Jun 6, 2020

CLA assistant check
All CLA requirements met.

@panesofglass panesofglass force-pushed the customoperation-overloads branch from 54537e3 to 95fcd9c Compare June 6, 2020 18:48
Nhowka and others added 3 commits June 6, 2020 13:55
- Check 1:1 by operation/method names instead of count
- Remove arg count check

(cherry picked from commit 854f080)
(cherry picked from commit 527eb54)
(cherry picked from commit cdc765d)
@panesofglass panesofglass force-pushed the customoperation-overloads branch from 95fcd9c to 3ee5a49 Compare June 6, 2020 18:55
@cartermp
Copy link
Contributor

cartermp commented Jun 6, 2020

Thanks for picking this up @panesofglass! In terms of tests, the best place to put them for now would be in the FSharpSuite here: https://github.com/dotnet/fsharp/tree/master/tests/fsharp/Compiler/Conformance

@panesofglass
Copy link
Contributor Author

Thanks for the tip, @cartermp. I was planning to take a gander at that tonight.

@panesofglass panesofglass force-pushed the customoperation-overloads branch 4 times, most recently from c7357ac to a5bc4ad Compare June 7, 2020 19:13
@panesofglass panesofglass force-pushed the customoperation-overloads branch from a5bc4ad to c6f4e47 Compare June 7, 2020 20:43
@panesofglass
Copy link
Contributor Author

panesofglass commented Jun 7, 2020

Looks like the [<ParamArray>] doesn't quite work correctly, though I cannot tell whether that is my implementation or something else. Also, external extensions do not appear to work with overloading, but that may again be related to the [<ParamArray>].

  X OverloadLib accepts overloaded internal and external extensions [829ms]
  Error Message:
   Compile had warnings and/or errors: [|C:\Users\ryanr\AppData\Local\Temp\tmpD9E9.fs (43,14)-(43,20) typecheck error This expression was expected to have type
    'ArraySegment<byte>'
but here has type
    'string'    ;
  C:\Users\ryanr\AppData\Local\Temp\tmpD9E9.fs (46,14)-(46,27) typecheck error This expression was expected to have type
    'byte []'
but here has type
    'string'    ;
  C:\Users\ryanr\AppData\Local\Temp\tmpD9E9.fs (46,28)-(46,32) typecheck error This expression was expected to have type
    'int'
but here has type
    'string'    ;
  C:\Users\ryanr\AppData\Local\Temp\tmpD9E9.fs (46,33)-(46,42) typecheck error This expression was expected to have type
    'int'
but here has type
    'string'    |]
  Stack Trace:
     at <StartupCode$FSharp-TestHelpers>[email protected](Tuple`2 tupledArg) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 525
   at FSharp.TestHelpers.CompilerAssert.compileAux(Boolean isExe, String[] options, String source, FSharpFunc`2 f) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 221
   at <StartupCode$FSharp-TestHelpers>[email protected](Unit _arg2) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 274
   at FSharp.TestHelpers.CompilerAssert.compile(Boolean isExe, String[] options, String source, FSharpFunc`2 f)
   at FSharp.TestHelpers.CompilerAssert.CompileExeAndRunWithOptions(String[] options, String source) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 522
   at FSharp.Compiler.UnitTests.ComputationExpressions.OverloadLibTest(Boolean inclInternalExt, Boolean inclExternalExt, String source) in C:\Users\ryanr\Code\OSS\fsharp\tests\fsharp\Compiler\Conformance\DataExpressions\ComputationExpressions.fs:line 770
   at FSharp.Compiler.UnitTests.ComputationExpressions.OverloadLib accepts overloaded internal and external extensions() in C:\Users\ryanr\Code\OSS\fsharp\tests\fsharp\Compiler\Conformance\DataExpressions\ComputationExpressions.fs:line 802

  X OverloadLib accepts overloaded internal extension methods [1s 538ms]
  Error Message:
   System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.Exception : FAILED TmFtZVxyXG5FbWF2, expected [|78uy; 97uy; 109uy; 101uy; 13uy; 10uy; 69uy; 109uy; 97uy; 105uy; 108uy; 13uy;
  10uy; 115uy; 115uy; 119uy; 111uy; 13uy; 10uy; 68uy; 101uy; 115uy; 99uy; 114uy;
  105uy; 112uy; 116uy; 105uy; 111uy; 110uy; 13uy; 10uy; 111uy; 102uy; 13uy; 10uy;
  99uy; 111uy; 110uy; 116uy; 101uy; 110uy; 116uy; 13uy; 10uy|], got [|78uy; 97uy; 109uy; 101uy; 13uy; 10uy; 69uy; 109uy; 97uy; 105uy; 108uy; 13uy;
  10uy; 115uy; 115uy; 119uy; 111uy; 13uy; 10uy|]
  Stack Trace:
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at FSharp.TestHelpers.Worker.ExecuteTestCase(String assemblyPath, String[] deps) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 48
   at FSharp.TestHelpers.Worker.ExecuteTestCase(String assemblyPath, String[] deps)
   at FSharp.TestHelpers.CompilerAssert.executeBuiltApp(String assembly, FSharpList`1 deps) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 182
   at <StartupCode$FSharp-TestHelpers>[email protected](Tuple`2 tupledArg) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 527
   at FSharp.TestHelpers.CompilerAssert.compileAux(Boolean isExe, String[] options, String source, FSharpFunc`2 f) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 221
   at <StartupCode$FSharp-TestHelpers>[email protected](Unit _arg2) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 274
   at FSharp.TestHelpers.CompilerAssert.compile(Boolean isExe, String[] options, String source, FSharpFunc`2 f)
   at FSharp.TestHelpers.CompilerAssert.CompileExeAndRunWithOptions(String[] options, String source) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 522
   at FSharp.Compiler.UnitTests.ComputationExpressions.OverloadLibTest(Boolean inclInternalExt, Boolean inclExternalExt, String source) in C:\Users\ryanr\Code\OSS\fsharp\tests\fsharp\Compiler\Conformance\DataExpressions\ComputationExpressions.fs:line 770
   at FSharp.Compiler.UnitTests.ComputationExpressions.OverloadLib accepts overloaded internal extension methods() in C:\Users\ryanr\Code\OSS\fsharp\tests\fsharp\Compiler\Conformance\DataExpressions\ComputationExpressions.fs:line 788
--Exception
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1639.Invoke(String message) in C:\Users\ryanr\Code\OSS\fsharp\src\fsharp\FSharp.Core\printf.fs:line 1639
   at TmpDD27.check[a](String msg, a actual, a expected)
   at <StartupCode$tmpDD28>.$TmpDD27.main@()
  X OverloadLib accepts overloaded methods [1s 226ms]
  Error Message:
   System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.Exception : FAILED TmFtZVxyXG5FbWF1, expected [|78uy; 97uy; 109uy; 101uy; 13uy; 10uy; 69uy; 109uy; 97uy; 105uy; 108uy; 13uy;
  10uy; 115uy; 115uy; 119uy; 111uy; 13uy; 10uy; 68uy; 101uy; 115uy; 99uy; 114uy;
  105uy; 112uy; 116uy; 105uy; 111uy; 110uy; 13uy; 10uy; 111uy; 102uy; 13uy; 10uy;
  99uy; 111uy; 110uy; 116uy; 101uy; 110uy; 116uy; 13uy; 10uy|], got [|78uy; 97uy; 109uy; 101uy; 13uy; 10uy; 69uy; 109uy; 97uy; 105uy; 108uy; 13uy;
  10uy; 115uy; 115uy; 119uy; 111uy; 13uy; 10uy|]
  Stack Trace:
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at FSharp.TestHelpers.Worker.ExecuteTestCase(String assemblyPath, String[] deps) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 48
   at FSharp.TestHelpers.Worker.ExecuteTestCase(String assemblyPath, String[] deps)
   at FSharp.TestHelpers.CompilerAssert.executeBuiltApp(String assembly, FSharpList`1 deps) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 182
   at <StartupCode$FSharp-TestHelpers>[email protected](Tuple`2 tupledArg) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 527
   at FSharp.TestHelpers.CompilerAssert.compileAux(Boolean isExe, String[] options, String source, FSharpFunc`2 f) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 221
   at <StartupCode$FSharp-TestHelpers>[email protected](Unit _arg2) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 274
   at FSharp.TestHelpers.CompilerAssert.compile(Boolean isExe, String[] options, String source, FSharpFunc`2 f)
   at FSharp.TestHelpers.CompilerAssert.CompileExeAndRunWithOptions(String[] options, String source) in C:\Users\ryanr\Code\OSS\fsharp\tests\FSharp.TestHelpers\CompilerAssert.fs:line 522
   at FSharp.Compiler.UnitTests.ComputationExpressions.OverloadLibTest(Boolean inclInternalExt, Boolean inclExternalExt, String source) in C:\Users\ryanr\Code\OSS\fsharp\tests\fsharp\Compiler\Conformance\DataExpressions\ComputationExpressions.fs:line 770
   at FSharp.Compiler.UnitTests.ComputationExpressions.OverloadLib accepts overloaded methods() in C:\Users\ryanr\Code\OSS\fsharp\tests\fsharp\Compiler\Conformance\DataExpressions\ComputationExpressions.fs:line 774
--Exception
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1639.Invoke(String message) in C:\Users\ryanr\Code\OSS\fsharp\src\fsharp\FSharp.Core\printf.fs:line 1639
   at TmpE324.check[a](String msg, a actual, a expected)
   at <StartupCode$tmpE325>.$TmpE324.main@()

@panesofglass
Copy link
Contributor Author

@isaacabraham this would really help with the things we discussed re: https://github.com/CompositionalIT/farmer

@isaacabraham
Copy link
Contributor

Mmmm. It feels like overloads in CEs is kind of a hidden feature at the moment that doesn't quite work. Supporting overloads would definitely be useful.

@cartermp
Copy link
Contributor

cartermp commented Jun 9, 2020

@dsyme what do you think of some of these test failures? There's some oddities in this space in general, but I'm not sure if these would be expected or if they're indicative of a different issue with overload resolution.

@NinoFloris
Copy link
Contributor

Beyond the ParamArray issue I found overloads with different arities aren't picked up when using @panesofglass workaround. Though maybe this will * just work * once all methods can be attributed? Worth a test, anyway.

@Nhowka
Copy link
Contributor

Nhowka commented Jul 21, 2020

When I tried to remove the artificial limitations in the past, the [<ParamArray>] and other overloads worked just fine. Maybe something changed between then and now if this became an issue...

@panesofglass
Copy link
Contributor Author

@Nhowka are my tests incorrect? Is there a better way to go about this?

@Nhowka
Copy link
Contributor

Nhowka commented Jul 26, 2020

I think it's probably just missing an open Extensions, so it's not getting the overload that accepts string, making it fail. Got the same error in fsi but worked after adding the open Extensions. Not sure how to run the same test locally to be honest, I don't know if it's just that.

@Nhowka
Copy link
Contributor

Nhowka commented Aug 7, 2020

The changes look good, however, it needs to be protected with a language version switch.

While I understand the reason, I'm not sure if I agree. This is an unbreaking change, in the sense that code that used to fail to compile when using a computation expression that had that kind of overload will now just work. Note that the computation expression builder itself used to compile with no problem, the error to compile were just when using the custom keywords.

In the RFC I added an example of that happening, the library was compiled with no warnings and then when the client tried to use it, the error happened. I think that making the code that failed to compile suddenly working wouldn't be that bad, but I don't know if there an existing policy to treat these cases...

@cartermp
Copy link
Contributor

cartermp commented Aug 7, 2020

Note that the langversion switch isn't about breaking changes or not. It's a means of separating preview features from non-preview features. Any new feature that is merged is preview, and we deliberately "promote" them to a language version when it makes sense. My mistake for approving right away, this needs a new case here: https://github.com/dotnet/fsharp/blob/master/src/fsharp/LanguageFeatures.fs#L36 and the associated check in both places in the typechecker.

Testing appears to use the preview flag already outside of the fsharpQA cases - @KevinRansom how should the fsharpqa cases be handled?

@Nhowka
Copy link
Contributor

Nhowka commented Aug 7, 2020

I understand it better now, makes sense!

@Nhowka
Copy link
Contributor

Nhowka commented Aug 8, 2020

For the feature string would it just need a new line on FSComp.txt or is something extra needed?

3380,parsEofInInterpolatedVerbatimString,"Incomplete interpolated verbatim string begun at or before here"
3381,parsEofInInterpolatedTripleQuoteString,"Incomplete interpolated triple-quote string begun at or before here"
3382,lexRBraceInInterpolatedString,"A '}}' character must be escaped (by doubling) in an interpolated string."
featureOverloadsForCustomOperations,"overloads for custom operations"
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe line around 1514 would be better to group the features together

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 moved it further up next to the line that says overloads are not allowed.

@panesofglass
Copy link
Contributor Author

@cartermp or @KevinRansom how do I set up the tests to pass now?

@dsyme
Copy link
Contributor

dsyme commented Aug 10, 2020

@panesofglass For the desktop_Release failure, you have baseline differences in neg60.fs, neg61,fs and neg87.fs.

There's a way to update the baselines on your local machine automatically (I need to look it up), or you can manually run and adjust and throw it back at CI. Here are three command lines yo ucan use to recreate the error files and replace the baseline files:

2020-08-08T02:44:16.5143188Z  D:\a\1\s\tests\FSharp.Test.Utilities\..\..\artifacts\bin\fsc\Release\net472\fsc.exe -r:System.Core.dll --nowarn:20 --define:COMPILED  --define:NEGATIVE --vserrors --warnaserror --nologo --maxerrors:10000 -a -o:neg60.dll neg60.fs 2>neg60.err


2020-08-08T02:44:18.0656712Z  D:\a\1\s\tests\FSharp.Test.Utilities\..\..\artifacts\bin\fsc\Release\net472\fsc.exe -r:System.Core.dll --nowarn:20 --define:COMPILED  --define:NEGATIVE --vserrors --warnaserror --nologo --maxerrors:10000 -a -o:neg61.dll neg61.fs 2>neg61.err

2020-08-08T02:44:48.1234110Z  D:\a\1\s\tests\FSharp.Test.Utilities\..\..\artifacts\bin\fsc\Release\net472\fsc.exe -r:System.Core.dll --nowarn:20 --define:COMPILED  --define:NEGATIVE --vserrors --warnaserror --nologo --maxerrors:10000 -a -o:neg87.dll neg87.fsx 2>neg87.err

You also have three failures in "fsharpqa"

2020-08-08T01:59:58.0125197Z Conformance\Expressions\DataExpressions\QueryExpressions (E_WhitespaceErrors01.fs) -- failed
2020-08-08T01:59:58.0130028Z Conformance\Expressions\DataExpressions\QueryExpressions (E_BadGroupValBy01.fs) -- failed
2020-08-08T01:59:58.0131689Z Conformance\Expressions\DataExpressions\QueryExpressions (E_BadGroupValBy02.fs) -- failed

Unfortunately they aren't showing here so you'll have to manually try to work out what the relevant command line is from env.lst in that directory, satisfy yourself there is no signficant regression (I doubt there is) and try to patch them up as well as you can

https://dev.azure.com/dnceng/public/_build/results?buildId=762398&view=ms.vss-test-web.build-test-results-tab

@cartermp
Copy link
Contributor

Sorry for all the hassle, especially the fsharpqa tests. They're really quite awful to adjust, but we're planning on moving them to be normal tests that are easy to run and diagnose

@panesofglass
Copy link
Contributor Author

@cartermp do you need me to rebase and/or merge commits to clean up the commit history?

@cartermp
Copy link
Contributor

@panesofglass we tend to use squash commits here, so it should be good to go.

@KevinRansom - want to re-review?

@cartermp
Copy link
Contributor

@KevinRansom this now correctly guards against the flag and all tests are updated. Looking good? I'd like to get this one in soon.

@cartermp
Copy link
Contributor

Thanks @panesofglass and @Nhowka!

@cartermp cartermp merged commit 97246af into dotnet:master Aug 13, 2020
@panesofglass panesofglass deleted the customoperation-overloads branch August 14, 2020 02:17
@realvictorprm
Copy link
Contributor

This is absolutely great! Thank you all!

@mastoj
Copy link

mastoj commented Aug 14, 2020

Awesome stuff. If this was in the box a month ago the pulumiprovider that I helped out on would be in a much better shape: https://github.com/UnoSD/Pulumi.FSharp.Extensions. Great to see this happen!

nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
…ns (dotnet#9400)

* Remove limitations on custom operation overloads

- Check 1:1 by operation/method names instead of count
- Remove arg count check

(cherry picked from commit 854f080)

* Updated baselines

(cherry picked from commit 527eb54)

* New error messages

(cherry picked from commit cdc765d)

* Add failing tests based on RFC

* Expand test cases for overloaded CE members

* open Extensions to fix tests

* Fix error with opening missing Extensions module

* Fix unit tests

* Give unique values for each check in CE overload tests

* Add regression scenarios to ensure current functionality does not break for computation expression overloads [FS-1056]

* Rename g to group per code review [FS-1056]

* Hide overloads for custom operations behind feature flag [FS-1056]

* Add feature flag to GetFeatureString

* Add featureOverloadsForCustomOperations to FSComps

* Update FSComp.txt [FS-1056]

* Update baselines [FS-1056]

* Revert "New error messages"

This reverts commit 3ee5a49.

Co-authored-by: Diego Esmerio <[email protected]>
Co-authored-by: Diego Esmerio <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.