-
Notifications
You must be signed in to change notification settings - Fork 789
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
F# 6.0 -> 7.0: A unique overload for method could not be determined #14302
Comments
A sample reproduction code: #!/usr/bin/env -S dotnet fsi
#r "nuget: TorchSharp-cpu, 0.99.0"
open TorchSharp
let xs = torch.zeros([|10L|], dtype=torch.float32) |
Thank you for filing it, this has definitely high impact. |
Might it be similar to #13731 ? |
@pkese out of curiosity, does it fix it when you're setting the language version to 6? <LangVersion>6</LangVersion> or Update: it seems, it's not. |
I suspect it might've been caused by the changes in #13673 |
I did some digging and this is a fun one, very much related to #13673 indeed. In that PR Nullable conversions became integrated into TDC (Type-Directed Conversion) proper, meaning every Nullable conversion is now also a TDC. This was done to fix bug #12860 but in doing so we've exposed a flaw in the way the compiler picks a candidate between two overloads that both have conversions. For the following overload set (minimized from TorchSharp): type ScalarType =
| Float32 = 0
type Tensor =
static member zeros(size: int64 array, dtype: System.Nullable<ScalarType>) =
Unchecked.defaultof<Tensor>
static member zeros(size: System.ReadOnlySpan<int64>, dtype: System.Nullable<ScalarType>) =
Unchecked.defaultof<Tensor> Given the call that reproduces the issue: Tensor.zeros([|10L|], dtype=ScalarType.Float32) Whether the first or second overload would match always had to rely on a conversion of some form for the second argument (from In F# 6 TDC was added and we narrowly avoided hitting this bug because overload 1 had no 'true' TDCs while the second overload would (as ROSpan has an implicit conversion for any array). Since F# 7 where Nullable conversions are now TDC conversions we get into the problematic part. For this call both applicable methods become marked as type directed under the new logic, the nullable argument causes the first one to be so and the ROSpan one will have two conversions applied, one for each argument. After this point our overload rules are not granular enough to pick a better candidate, the TDC status in the resolution is only granular up to a candidate, not per argument. I just want to clarify that before #13673 this was already a problem. The issue is just expanded now that Nullable is included, causing it to show up more frequently. Take the following example: type Tensor =
static member zeros(size: int64 array, dtype: int64) =
Unchecked.defaultof<Tensor>
static member zeros(size: System.ReadOnlySpan<int64>, dtype: int64) =
Unchecked.defaultof<Tensor>
let test() = Tensor.zeros([|10L|], 1) And try this on sharplab or an F# 6 compiler (the repro still compiles over there which must mean it's not yet on F# 7) You'll notice that calls like these also produce the same issue on F# 6, it's just problematic that we've expanded the issue to cover Nullable, which likely sees quite a bit more use of this feature than numeric and op_implicit conversions. There are also fairly big verbosity benefits to using it. We have a few options, from least to more involved/risky:
My thoughts on each option:
@dsyme / @vzarytovskii I'm available on slack or we can hop on a call if that helps. |
Yeah, won't likely be an option for us, we would like to properly test such fix before we service it. |
What do you mean by that? It would mostly mean reverting this specific commit da5d49b |
Oh, I misunderstood the statement. Yeah, reverting it might me an option, or just hiding new logic under language preview flag. |
My instinct is we should indeed prefer overloads involving some kinds of TDC conversions over others. Roughly in preference order:
@NinoFloris What's your judgment - would that resolve this and is it implementable? Thanks! :) |
Can I mark as closed by #14319 now ? |
* Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 1997730 (#13925) (#14041) Co-authored-by: Vlad Zarytovskii <[email protected]> * Merge main to release/dev17.5 (#14043) Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Don Syme <[email protected]> Co-authored-by: Tomas Grosup <[email protected]> Co-authored-by: Edgar Gonzalez <[email protected]> Co-authored-by: Eugene Auduchinok <[email protected]> Co-authored-by: Chet Husk <[email protected]> Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: Florian Verdonck <[email protected]> Co-authored-by: Petr <[email protected]> Co-authored-by: Petr Pokorny <[email protected]> Co-authored-by: Theodore Tsirpanis <[email protected]> * Update FSharp.Editor.fsproj I believe a bad merge happened, this line is not in main. And the file does not exist in either branch. * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2014480 (#14049) * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2016907 * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2016985 * XLF * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2017073 * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2017391 * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2017391 * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2018131 (#14089) * Bugfix: Ref assemblies contained .property definitions at the wrong type in generated IL (#14093) * Bugfix: Ref assemblies contained property definitions at the wrong type * Better comment * Update versions for dev17.4 (#14102) * Update versions for dev17.5 (#14100) * Merge main to release/dev17.5 (#14098) * Add SynType.Or. (#14058) * Add SynType.Or for generic constrains in the form (^A or ^B):... * Change ty1.Equals(ty2) to call static op_Equality (#13028) Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Don Syme <[email protected]> Co-authored-by: Florian Verdonck <[email protected]> Co-authored-by: Rustam <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Don Syme <[email protected]> * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2023680 (#14133) * Disable ref assemblies in e2e tests (#14135) Disable reference assemblies for e2e test of type providers Co-authored-by: Adam Boniecki <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]> * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2024009 (#14139) * Downgrade SDK, rc2 is failing signing (#14146) * Generate SBOM for Fsharp (#14029) (#14169) * Generate Sbom * pass ci flag * update * Sbom generation * Fix for trimming tests: Added nuget.org source + explicit source mapping for FSharp.Core * Update Build.ps1 Tweaks to handle useGlobalNugetCache Co-authored-by: Kevin Ransom (msft) <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Kevin Ransom (msft) <[email protected]> Co-authored-by: Epsitha Ananth <[email protected]> Co-authored-by: Kevin Ransom (msft) <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Kevin Ransom (msft) <[email protected]> * Update Arcade & Put automated pool provider usage functionality into Dev17.4 branch (similar to PR in main now but will not be backported here) (#14177) * [release/dev17.4] fix metadata failure due to double integration of signature (#14190) * fix metadata failure due to double duplication * fix metadata failure due to double duplication Co-authored-by: Don Syme <[email protected]> * Global.json * [release/dev17.4] Don't emit IsReadOnlyAttribute if not available. (#14281) Co-authored-by: nojaf <[email protected]> * Fixed package versions to publicly available (#14291) * Fixed package versions to publicly available * Update Versions.props Microsoft.Build.* to 17.4.0 Co-authored-by: Kevin Ransom (msft) <[email protected]> * Update Versions.props * Prefer nullable over other conversions, fixes #14302 * Replace ROSpan for DateTimeOffset as op_Implicit target, ROSpan is not defined on all test TFMs * [release/dev17.4] F# 7 fixes (#14322) * WIP: Fix for calling init-only setter via srtp call + allow calling special-named functions via srtp * Fix 14097 Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Tomas Grosup <[email protected]> Co-authored-by: Don Syme <[email protected]> * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2051937 (#14381) * Deploy System.Diagnostics.DiagnosticSource to Tools folder (#14417) * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2059214 (#14427) * Revert "IL: optimize attribute cluster reading (#13821)" This reverts commit 179db4e. * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2067933 (#14472) * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2067933 * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2067933 * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2068561 (#14474) * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2068115 * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2068115 Co-authored-by: Tomas Grosup <[email protected]> * Localized file check-in by OneLocBuild Task: Build definition ID 499: Build ID 2077478 (#14533) * Revert "Merge branch 'release/dev17.5' of https://github.com/dotnet/fsharp into release/dev17.5" This reverts commit 4d222de, reversing changes made to 2e92791. * Update azure-pipelines.yml * Merge main to release/dev17.5 (#14562) Co-authored-by: Petr <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Don Syme <[email protected]> Co-authored-by: Tomas Grosup <[email protected]> Co-authored-by: Edgar Gonzalez <[email protected]> Co-authored-by: Eugene Auduchinok <[email protected]> Co-authored-by: Chet Husk <[email protected]> Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: Florian Verdonck <[email protected]> Co-authored-by: Petr <[email protected]> Co-authored-by: Petr Pokorny <[email protected]> Co-authored-by: Theodore Tsirpanis <[email protected]> Co-authored-by: Kevin Ransom (msft) <[email protected]> Co-authored-by: Rustam <[email protected]> Co-authored-by: Adam Boniecki <[email protected]> Co-authored-by: Adam Boniecki <[email protected]> Co-authored-by: Epsitha Ananth <[email protected]> Co-authored-by: Kevin Ransom (msft) <[email protected]> Co-authored-by: Matt Galbraith <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nino Floris <[email protected]>
Please provide a succinct description of the issue.
I had the following TorchSharp code working fine in F# 6.0:
After upgrading to F# 7.0 the compiler started complaining:
It does work in F# 7.0 if I change the code to:
... but having to sprinkle this all over the code (in this way) is clumsy and hinders readability.
Yes, there's a workaround,
but from a usability perspective, I'd call this a regression.
The text was updated successfully, but these errors were encountered: