Skip to content

Mysterious type inference changes break safe stack apps #4343

Closed

Description

@forki

A recent change in type inference (probably related to SRTPs) breaks all safe stack apps that use task {}

Original report: SAFE-Stack/SAFE-BookStore#283

Repro steps

I tried to create a repro here see #4285 but that did not work. But repro is working on bookstore SAFE-Stack/SAFE-BookStore#293

Expected behavior

No further type hints needed

Actual behavior

We need a lot of new type annotations to make it compile

Known workarounds

Adding type hints

Activity

  1. realvictorprm commented on Feb 13, 2018

    @realvictorprm
    Contributor

    I wasn't aware of such a bug. Sounds worse I hope we know soon what the cause is.

  2. dsyme commented on Feb 13, 2018

    @dsyme
    Contributor
  3. forki commented on Feb 13, 2018

    @forki
    ContributorAuthor

    yes. sorry I don't have better repro yet.

  4. dsyme commented on Feb 13, 2018

    @dsyme
    Contributor

    I'll take a look. I haven't yet verified the issue, but noting #4173 as a possible cause

  5. dsyme commented on Feb 13, 2018

    @dsyme
    Contributor

    @forki Is this the same issue as giraffe-fsharp/Giraffe#222 (comment)?

  6. forki commented on Feb 13, 2018

    @forki
    ContributorAuthor

    no that one was different and is solved by opening correct namespace. forki-patch-3 already has all namespaces correctly opened and would work against .net cli 2.1.3 - only the update to 2.1.300-preview1-008009 makes it break.

    you should be able to repro by running "build.cmd run" on that branch

  7. dsyme commented on Feb 13, 2018

    @dsyme
    Contributor

    @forki I've confirmed that #4173 is indeed the cause of this change in behaviour.

    This is difficult, as that PR was itself a reversion of a change which @gusty reports as causing a regression. We thought that the change was innocuous but it seems the kind of inline/SRTP/object-programming code in TaskBuilder.fs has picked up a dependency on the interim behaviour.

    By far the best interim solution would be to simplify TaskBuilder.fs so it doesn't depend on this kind of subtlety and works with or without the change in #4173

  8. gusty commented on Feb 13, 2018

    @gusty
    Contributor

    I think if this really caused a regression then trying the code in F# previous to 4.1 should also fail.
    Is there a minimal repro snippet?

  9. forki commented on Feb 13, 2018

    @forki
    ContributorAuthor

    I think @rspeele and @gerardtoconnor are the experts when it comes to the task { } - I'm not sure if / how to rewrite it.

  10. gusty commented on Feb 13, 2018

    @gusty
    Contributor

    I agree with @dsyme in that it might be worth fixing the taskbuilder code instead.
    I can give it a try, if you send me a repro.

  11. forki commented on Feb 13, 2018

    @forki
    ContributorAuthor

    @gusty repro is described above. that's all I have

  12. dsyme commented on Feb 13, 2018

    @dsyme
    Contributor

    @gusty I'll work on a minimal repro, we'll need it to pin down behaviour either way.

    Status:

    Questions:

    I think if this really caused a regression then trying the code in F# previous to 4.1 should also fail.

    We can try to verify this. It's plausible as the TaskBuilder.fs code is using SRTP very extensively in a way I wasn't seeing prior to 4.1

  13. gusty commented on Feb 13, 2018

    @gusty
    Contributor

    Are we 100% sure that #4173 was a clean revert of #1650?

    I can double check it, but I remember I did it very carefully.

    Also, you mention #3366 in the description of #4173. Is the idea that #4173 reverts both #1650 and #3366?

    Yes, it reverts also #3366 which was a case not handled in #1650 so now it's not needed.

    We can try to verify this. It's plausible as the TaskBuilder.fs code is using SRTP very extensively in a way I wasn't seeing prior to 4.1

    Another possibility is to fix the root cause of the issue with the taskbuilder code. I mean #1650 is wrong, now I'm sure about it, because the reasoning behind it was wrong, but that doesn't mean that it could have accidentally workaround an existing bug (there are many), if that's the case, we should attack that specific bug instead. So the main question here is, regardless of the status of the F# compiler, is the taskbuilder code correct? Should it compile? (I'm having a look at it right now)

  14. 16 remaining items

  15. gusty commented on Feb 18, 2018

    @gusty
    Contributor

    I can confirm now, that writing the TaskBuilder with the overload patterns I use in FSharpPlus, solves this issue.
    Actually it looks a bit more readable to me and also works in F# 4.0 and lower.

    @rspeele I can do a PR to the original project, so you can have a look at the code and test it.

  16. gusty commented on Feb 19, 2018

    @gusty
    Contributor

    FYI here's the PR with the fix rspeele/TaskBuilder.fs@9db31f6

  17. forki commented on Feb 19, 2018

    @forki
    ContributorAuthor

    @gusty are they working with both versions of the compiler?

  18. gusty commented on Feb 19, 2018

    @gusty
    Contributor

    @forki Yes, this code works universally in all versions of F# with or without #1650 and it uses sort of a pattern I was using since 2010 so we can say it's bulletproof overloading code ;)

  19. forki commented on Feb 19, 2018

    @forki
    ContributorAuthor
  20. gusty commented on Feb 19, 2018

    @gusty
    Contributor

    Glad to help.

    Just to be clear, I still think that the F# compiler should be able to compile the repro with the original code, but not at the cost of #1650 which introduced more problems than solutions.

    Independent of that discussion and current status of the compiler, I suggest that taskbuilder is updated with this pattern, which seems to be more robust and easier to read, since you have all overloads in one place and the priority is explicit whereas in the original code you have to open, close modules, extensions and add comments like "see further below more overloads for ..." and so on.

  21. forki commented on Feb 19, 2018

    @forki
    ContributorAuthor

    sigh taskbuilder broke. rspeele/TaskBuilder.fs#15

  22. gusty commented on Mar 1, 2018

    @gusty
    Contributor

    @dsyme Now that TaskBuilder.fs is fixed, can we consider re-re-reverting #1650 and avoid another accidentally introduced dependency?

  23. dsyme commented on Mar 2, 2018

    @dsyme
    Contributor

    @gusty We'll just have to keep things stable for a while, and can't add/remove #1650 again.

    You can, however, add both before and after versions of TaskBuidler.fs as test cases to this repo please? Then we pin down behaviour both positive and negative, and make sure any changes we make going forward have known effect.

  24. gusty commented on Mar 5, 2018

    @gusty
    Contributor

    But precisely in order to keep things stable I strongly recommend not to include #1650, the sooner we remove it, the better.

    It will not only produce breaking changes, it will also break the compiler, see below a quick example I found today, but there are more. I encountered this error at least twice a month.

    image

    Remember the headaches caused until it was patched with #3366 , otherwise read again the conversations there, then think about it, considering that there are still more scenarios today where that internal error pops up. We would need more patches like #3366

    Also keep in mind that the only known regression is in TaskBuilder, which is already fixed and in anycase that specific problematic version of TaskBuilder doesn't work in most F# versions (many companies still use F# 4.0) and it also has other incompatibility problems, as the one recently reported by @forki

    Worst case, if you still insist to keep #1650 , I can try to find the time to investigate why the old TaskBuider didn't compile and try to solve that specific problem in the constraint solver.

  25. dsyme commented on Mar 12, 2018

    @dsyme
    Contributor

    But precisely in order to keep things stable I strongly recommend not to include #1650, the sooner we remove it, the better.

    I'm not sure I understand. #1650 has been in for 18 months now and is now the "stable" state. I can see we need to remove the internal error showing above, but we need to do it in a way that doesn't change what does and doesn't compile.

    Anyway, please add a specific new issue for the current problems (e.g. the internal error), thanks :)

  26. gusty commented on Mar 12, 2018

    @gusty
    Contributor

    OK, just wanted to make sure you understand what's the current status, which is not "great" from my viewpoint.

    I will create a separate issue, and add tests and repros.

    I have a question for you, a very important question indeed: Do you think my reasoning behind #1650, (regarding stop exploring solutions in case of failure to resolve overload) was correct, incorrect, something in-between?

  27. dsyme commented on Mar 12, 2018

    @dsyme
    Contributor

    @gusty I keep staring at that PR thinking "why did this make such a big difference". And in particular why this line should make such a difference

    I think you should add a new issue that shows the very simplest scenario where commenting/uncommenting that line makes a major difference, and lets reason through it from there. And I assume that when that line is commented out, then #1650 is a noop?

  28. dsyme commented on Mar 12, 2018

    @dsyme
    Contributor

    There is also this change and I'd like to know if/when that makes a difference.

  29. gusty commented on Mar 12, 2018

    @gusty
    Contributor

    And I assume that when that line is commented out, then #1650 is a noop?

    Yes.

    There is also this change and I'd like to know if/when that makes a difference.

    It's hard to remember my reasoning at that time, but I think I had studied a case where that short-circuit lead to a failure to resolve an overload, and in that particular scenario by observing the fact that there was an Unresolved-Overload and signaling it, lead to explore and select the good one.

    Looks like we'll have to revisit it, I will try to find the example I was analyzing, I think I know which one is, then figure out a better fix which solves the current problems (like the one in the taskbuilder) without causing regressions, and ideally solving more problems like that (there are many cases where I hit the error message saying that the default 'obj' was inferred and no overloads match that type).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-HighReady

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions