dotnet / dotnet/fsharp

Revisit type-checking logic

Open
#16,436 11 comments 3 reactions 0 assignees View on GitHub
Area-Compiler-Checking Feature Request Needs-design
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

**Is your feature request related to a problem? Please describe.**

Imagine the following:

A.fs
```fsharp
module A

let f (a: int) : int =
match a with
| 0 -> 0 + 1
| 1 -> 1 + 1
| 2 -> 2 + 1
| 3 -> 3 + 1
| 4 -> 4 + 1
| 5 -> 5 + 1
| 6 -> 6 + 1
| 7 -> 7 + 1
| 8 -> 8 + 1
| 9 -> 9 + 1
| 10 -> 10 + 1
| 11 -> 11 + 1
| 12 -> 12 + 1
| 13 -> 13 + 1
| 14 -> 14 + 1
| 15 -> 15 + 1
| 16 -> 16 + 1
| 17 -> 17 + 1
| 18 -> 18 + 1
| 19 -> 19 + 1
| 20 -> 20 + 1
...
| 9001 -> 9001 + 1
| i -> i + 1
```

B.fs
```fsharp
module B

open A

let g = f 0
```

If I open `B` in my editor. Most editors will perform an `FSharpChecker.ParseAndCheckFileInProject` for `B.fs`. That will need to type-check `A.fs` and thus come up with a decision tree for the match expression in `f`.

The creation of this decision tree could potentially be expensive, depending on the complexity of the patterns and isn't a hard requirement for opening `B.fs` in my editor.

**Describe the solution you'd like**

I would expect type inference can happen without the construction of the pattern match decision tree and could speed up the IDE experience.

Thinking out loud, it would be great if we could move certain logic to a post-inference phase and invoke it on demand from the CheckResults. I'm certain, some other checks could be moved to this phase as well, making the strict type-check logic a bit lighter.

I'm not sure about the API and implications, but something along the lines of:

```fsharp
let _, checkResults = checker.ParseAndCheckFileInProject(bPath, 1, bSourceText, sampleProjectOptions) |> Async.RunSynchronously
let checkResults =
match checkResults with
| FSharpCheckFileAnswer.Succeeded checkResults -> checkResults
| FSharpCheckFileAnswer.Aborted -> failwith "todo"

let postInferenceResults = checkResults.GetPostInferenceResults()
```

could work, maybe?

**Describe alternatives you've considered**

\/

**Additional context**

This was brought up by @auduchinok a couple of times, I think it is worth looking into.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.