fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

[WIP] Improve initialization circularity analysis

Open dsyme opened this issue 3 years ago • 5 comments

This is a first cut at improving the circularity analysis for initialization, which has had a couple of bugs known for a while now

  • This case was being reported when it is not problematic: https://github.com/dotnet/fsharp/issues/7451

  • This case was not being reported when it is problematic:

let rec f(): int = h()
and g = f()
and h() = g + 1
  • This case was not being reported when it is problematic. The definition was being allowed, but producing invalid results at runtime (the field2 contained a null value). Instead the definition should not be allowed.
type RecordType = { field1 : string; field2 : RecordType option; field3 : (unit -> RecordType * string) }
type C() =    
    let rec recordtype1 : RecordType = { field1 = "field1"; field2 = Some(recordtype1); field3 = ( fun () -> (recordtype1, "")  )}
    member x.V = recordtype1
C().V
  • [ ] Get it through CI and bootstrap and see what tests get affected.
  • [ ] Protect using a language feature flag

dsyme avatar Apr 04 '22 10:04 dsyme

@dsyme It doesn't seem too much related, but maybe you could also take a look at https://github.com/dotnet/fsharp/issues/7931 or https://github.com/dotnet/fsharp/issues/5795 while working on this PR, since they're also about issues arising when having a recursive module/namespace?

auduchinok avatar Apr 04 '22 11:04 auduchinok

@dsyme It doesn't seem too much related, but maybe you could also take a look at https://github.com/dotnet/fsharp/issues/7931 or https://github.com/dotnet/fsharp/issues/5795 while working on this PR, since they're also about issues arising when having a recursive module/namespace?

That's a different class of bugs - not related to initialization but rather recursive type checking.

dsyme avatar Apr 04 '22 13:04 dsyme

/azp run

dsyme avatar Jul 12 '22 13:07 dsyme

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Jul 12 '22 13:07 azure-pipelines[bot]

(The CI keeps timing out on this - I think the algorithm to find circularities in the dependency graphs is not fast enough)

dsyme avatar Jul 12 '22 22:07 dsyme