fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

FS3511 warning when using `for...in` in task CE with .NET SDK 6.0.400 in Release builds

Open sasmithjr opened this issue 3 years ago • 6 comments

In the latest SDK (6.0.400), I'm receiving a FS3511 warning with for...in loops in task when building for Release. This warning wasn't present in previous SDKs (e.g. 6.0.302)

Repro steps

  1. In a new console application, replace Program.fs with the following code:
let v =
    task {
        for value in [1;2;3] do
            printfn $"{value}"
    }
    
printfn "Hello from F#"
  1. dotnet build -c Release

Can repro with https://github.com/sasmithjr/FS3511-repro-for..in

Expected behavior

Builds without warning

Actual behavior

Receive the warning warning FS3511: This state machine is not statically compilable. A resumable code invocation at '(2,4--2,8)' could not be reduced. An alternative dynamic implementation will be used, which may be slower. Consider adjusting your code to ensure this state machine is statically compilable, or else suppress this warning.

Known workarounds

Suppressing the warning or using collection iter functions.

Related information

  • Operating system: macOS 12.5 on an M1 MBP
  • .NET Runtime kind (.NET Core, .NET Framework, Mono) .NET Core, SDK 6.0.400

Thanks for the help, and please let me know if I can provide anymore info.

sasmithjr avatar Aug 09 '22 22:08 sasmithjr

Might be worth checking if this fixed in VS and VS4Mac 17.3 as I think there was a fix a similar code generation BUG see https://github.com/dotnet/fsharp/pull/13415 ?

edgarfgp avatar Aug 10 '22 08:08 edgarfgp

I encountered the exact same issue a few days ago, but it only shows up when I build in Release mode. Debug mode doesn't seem to give me any warning.

Tried today building against dotnet 6.0.303 and 6.0.400. Both have the same behavior: no warning in debug build, warning FS3511 in release mode because of for .. in .. do inside a task.

TimLariviere avatar Aug 10 '22 08:08 TimLariviere

Might be worth checking if this fixed in VS and VS4Mac 17.3 as I think there was a fix a similar code generation BUG see #13415 ?

No, I pretty sure it's a different issue. But that fix might've caused it to break in .400.

vzarytovskii avatar Aug 10 '22 10:08 vzarytovskii

I encountered the exact same issue a few days ago, but it only shows up when I build in Release mode. Debug mode doesn't seem to give me any warning.

Correct about only in Release mode. I’m not sure how I wrote the whole bug report and didn’t explicitly state that but included the -c Release in the repro steps lol I edited the original issue to make that a smidge more clear.

sasmithjr avatar Aug 10 '22 10:08 sasmithjr

We have several functions with for ... in inside a Task CE, but only some of them are now getting the warning (an error in our project). I'm tempted to suppress it for the moment.

jcmrva avatar Aug 10 '22 20:08 jcmrva

13415 is totally separate issue of this.

  • 13415 is a fix for the situation where F# did incorrect things (corrupt program state) when the warning FS3511 happens.
  • This issue is that the warning happens.

As Tim said this issue is not related to 6.0.400 and happened also before.

Thorium avatar Aug 11 '22 07:08 Thorium

I'm closing as a duplicate of this: https://github.com/dotnet/fsharp/issues/12038

dsyme avatar Aug 16 '22 11:08 dsyme

I'm also seeing this crop up in CI, whereas it wasn't there previously (for the same code). As the OP describes, this specifically happens when using for ... in in a task CE.

As Tim said this issue is not related to 6.0.400 and happened also before.

@TimLariviere said this happened in 6.0.303. @sasmithjr said in the OP that this did not happen with 6.0.302. There's no inconsistency; the behavior seems to have been introduced in 6.0.303.

I'm closing as a duplicate of this: #12038

~Considering the above, how is this a duplicate of #12038? This has nothing to do with task CEs defined as top-level values.~ Edit: Oops, failed to read the OP example carefully enough, as well as my own code. It is indeed a top-level value in both cases. 😳 In any case, something evidently changed in 6.0.303, which was released long after #12038.

cmeeren avatar Sep 14 '22 10:09 cmeeren

Sorry I didn't see that this got closed and couldn't follow up.

I'm closing as a duplicate of this: https://github.com/dotnet/fsharp/issues/12038

So that is an issue and it is the issue that I presented in my original comment, but it's actually not the issue I encountered in my actual codebase lol when I was trying to recreate a smaller version of the problem to reproduce it for this issue, I accidentally reproduced the top level issue and assumed it was the warning I was bumping in to in my codebase.

In my production code base, tasks (in functions in modules) with for ... in over arrays of tuples produce the warning. Repro code here.

It seems @cmeeren called out a warning with tuples in this comment. I'm not sure if it's the exact same issue, and I'm not sure if it's being explicitly tracked, though.

Want me to update this main comment in this issue for better tracking? Or don't worry about it?

sasmithjr avatar Sep 14 '22 12:09 sasmithjr