-
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
Witnesses made visible in FCS #9510
Conversation
This is great, @dsyme, thanks a lot! I can PR some tests to this branch next week with SRTP samples that have been reported recently as not being resolved correctly by Fable 👍 |
@dsyme , this is marked as wip, is it still a wip? |
@dsyme I've built FCS from this branch and I'm testing it with Fable: https://github.com/fable-compiler/Fable/blob/1ed140e4ffacf232ca5d14e5bee2e48e5b1c3570/src/Fable.Transforms/FSharp2Fable.fs#L548-L562 It's working but I'm facing a couple of problems:
For example I get the exception when trying to parse any of the following texts (note the message always says "list2 is 1 element shorter than list1"): type Point =
{ x: int; y: int }
static member Zero = { x=0; y=0 }
static member Neg(p: Point) = { x = -p.x; y = -p.y }
static member (+) (p1, p2) = { x= p1.x + p2.x; y = p1.y + p2.y }
type MyNumber =
| MyNumber of int
static member Zero = MyNumber 0
static member (+) (MyNumber x, MyNumber y) =
MyNumber(x + y)
static member DivideByInt (MyNumber x, i: int) =
MyNumber(x / i)
type MyNumberWrapper =
{ MyNumber: MyNumber }
module ArrayTests =
testCase "Array.average works with custom types" <| fun () ->
[|MyNumber 1; MyNumber 2; MyNumber 3|] |> Array.average |> equal (MyNumber 2)
testCase "Array.averageBy works with custom types" <| fun () ->
[|{ MyNumber = MyNumber 5 }; { MyNumber = MyNumber 4 }; { MyNumber = MyNumber 3 }|]
|> Array.averageBy (fun x -> x.MyNumber) |> equal (MyNumber 4)
testCase "Array.sum with non numeric types works" <| fun () ->
let p1 = {x=1; y=10}
let p2 = {x=2; y=20}
[|p1; p2|] |> Array.sum |> equal {x=3;y=30}
testCase "Array.sumBy with non numeric types works" <| fun () ->
let p1 = {x=1; y=10}
let p2 = {x=2; y=20}
[|p1; p2|] |> Array.sumBy Point.Neg |> equal {x = -3; y = -30}
testCase "Array.sum with non numeric types works II" <| fun () ->
[|MyNumber 1; MyNumber 2; MyNumber 3|] |> Array.sum |> equal (MyNumber 6)
testCase "Array.sumBy with non numeric types works II" <| fun () ->
[|{ MyNumber = MyNumber 5 }; { MyNumber = MyNumber 4 }; { MyNumber = MyNumber 3 }|]
|> Array.sumBy (fun x -> x.MyNumber) |> equal (MyNumber 12) I will try to convert these into tests for this repository and send a PR tomorrow. |
@alfonsogarciacaro Thank you so much for trialling this, I'll take a look at the problems you mention and get things under test too. |
Do you know if you were using the FSharp.Core from a nuget package (without witness passing) or the freshly built FSharp.Core (with witness passsing) |
Ah, I had a feeling it might be related to FSharp.Core. I was indeed using the one from Nuget, let me try with a freshly built one. |
Well, we need to be robust when using the nuget one, I was just more asking for my own information when I look into this |
Hmm, I tried using the As a side note, I must say that building this repo in macOS is a breeze compared to what it used to be. Kudos to everybody involved in improving this! |
FYI @dsyme @alfonsogarciacaro we are planning on release FCS 38 alongside F# 5, which is just in a few short weeks. If this is important to get in by then, we should prioritize addressing all outstanding issues with this one so that it's not a mad rush to publish. |
For what it concerns Fable, right now we are using a custom build of FCS so we don't depend on the package, so please don't rush things just to let this in, we can build from this repo later (we can even build from the branch). Although other projects like Websharper may do be waiting for this to be included in the FCS package, see dotnet-websharper/core#1113 |
In contrast, in the
Line 381 in 886205d
|
@alfonsogarciacaro Thanks, I'm setting things up to repro your situation I assume the README in
|
Actually I guess I want this branch service_slim_fcsw -> ncave/service_slim_fcsw |
@ncave I'm have some trouble building
after running
in that branch. I'll try various techniques to unblock |
@dsyme Yes, the instructions are correct. And for the witnesses you are correct it is
Actually , the |
A full script to recompile FCS and test it with Fable, assuming you're in Fable directory and
|
OK, the problem with List.sum repros in main as a regression when taking quotations of code involving List.sum (when trying to generate the quotation data). @cartermp This is a regression, I presume we may see this in the wild. I will add a separate issue for this. type Point =
{ x: int; y: int }
static member Zero = { x=0; y=0 }
static member (+) (p1, p2) = { x= p1.x + p2.x; y = p1.y + p2.y }
let p1 = {x=1; y=10}
let p2 = {x=2; y=20}
<@ List.sum [p1] @> |
Tracked here: #10364 |
@alfonsogarciacaro I think I'm doing this right, that QuickTest now seems to pass:
|
This is ready once @alfonsogarciacaro and @ncave confirm it works for Fable without additional issues |
This is awesome @dsyme, thanks a lot for all your help! I've merged your latest changes and all Fable tests are passing now 🎉 🎉 🎉
The performance fix is also very welcome! So far when we were building active patterns by composing The trial by fire will now be to compile FSharpPlus with Fable ;) |
This is great. This PR is now ready to merge
Just a word on this: that library is complex and relies on baroque aspects of SRTP resolution that use the feature in ways that have never been recommended F# practice, and which to be honest I believe make for a poor user experience (e.g. in error messages, simplicity and compiler performance, let alone the problem I have with throwing the Functor/Applicative/... computational abstractions at beginners who deeply don't need them). I occasionally use it as a stress test, and use it as a way to isolate out test cases that capture the exact nature of those baroque corners, and it's useful for flushing those out. It's those individual extracted tests - the existing ones are already in this repo - that I consider the acceptance criteria. If the library does cause problems, please extract out a minimal test case, and we'll fix it as a separate bug. |
@KevinRansom @TIHan @cartermp Can I have a review on this please? It's ready to go in. |
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 for this Don
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 - been following along as this progressed. Lots of formatting changes but they're all for the better.
The release candidate of Fable 3 has been published with these changes and it's working flawlessly (at least in my tests. Thanks again for all your work @dsyme! Also, not entirely sure if it's all due to the performance fix in this PR but I made another simple benchmark of the compiler and the Fable part compilation (after FCS ParseAndCheck) is now around 25% faster! 🚀 This is in the addition to the performance improvements that were already presented at F# eXchange. |
Awesome! So exciting |
Co-authored-by: Don Syme <[email protected]>
This is an FCS feature requested by @alfonsogarciacaro for Fable and also relevant to WebSharper and others
It surfaces the information about witness passing through the FCS API
This will make F# transpilers more semantically accurate
The key additions can be seen in the signatrue files, e.g.
TODO