Skip to content
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

Design doc on reusing typechecking results #17368

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b9eca66
First thoughts
psfinaki Jun 27, 2024
73871a9
Merge branch 'main' into reuse-typecheck
KevinRansom Jun 29, 2024
884eca9
up
psfinaki Jul 9, 2024
3d375e8
Cleanup
psfinaki Jul 23, 2024
82937ec
up
psfinaki Aug 26, 2024
af6afbe
Update reusing-typecheck-results.md
psfinaki Aug 27, 2024
93faff2
Update reusing-typecheck-results.md
psfinaki Sep 11, 2024
4b0ab16
Update docs/reusing-typecheck-results.md
psfinaki Sep 12, 2024
bb26f18
Update docs/reusing-typecheck-results.md
psfinaki Sep 12, 2024
03d353c
Merge remote-tracking branch 'upstream/main' into reuse-typecheck
psfinaki Sep 12, 2024
9c9656e
Merge branch 'reuse-typecheck' of https://github.com/psfinaki/fsharp …
psfinaki Sep 12, 2024
a5121f3
clarify
psfinaki Sep 12, 2024
f43cb91
Update docs/reusing-typecheck-results.md
psfinaki Sep 12, 2024
9f15e98
Update reusing-typecheck-results.md
psfinaki Sep 12, 2024
ea3d96c
Update docs/reusing-typecheck-results.md
psfinaki Sep 12, 2024
ec563d0
Update reusing-typecheck-results.md
psfinaki Sep 12, 2024
a4ad14c
remove tast - il details
psfinaki Sep 12, 2024
b5747c8
Update reusing-typecheck-results.md
psfinaki Sep 12, 2024
33e40b5
Update reusing-typecheck-results.md
psfinaki Sep 13, 2024
c32eec4
Update reusing-typecheck-results.md
psfinaki Sep 13, 2024
ff6f1bd
Fix English
psfinaki Sep 26, 2024
1776b0c
Update reusing-typechecking-results.md
psfinaki Oct 31, 2024
2a3ee52
Update reusing-typechecking-results.md
psfinaki Oct 31, 2024
af1facb
Merge remote-tracking branch 'upstream/main' into reuse-typecheck
psfinaki Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/reusing-typecheck-results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: Reusing typecheck results
category: Compiler Internals
categoryindex: 200
index: 42
---

# Reusing typecheck results between compiler and tooling runs

Caching and reusing typecheck results between compiler and tooling runs will be an optimization technique aimed at improving the performance and efficiency of the F# development experience.

### Why is it important

- **Performance**. Recomputing type information for large projects is time-consuming. By caching the results, subsequent runs can skip this step, leading to faster builds.

- **IDE responsiveness**. IDEs can provide faster IntelliSense, code navigation, and other features if they can quickly access cached type information.
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

- **Error reduction**. Consistent typechecking results help avoid scenarios where slight differences between runs could cause different errors or warnings to be produced.

### General considerations

- The technique will be implemented separately for the compiler and tooling, for better granularity and trackability.
psfinaki marked this conversation as resolved.
Show resolved Hide resolved
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

- Caching data will likely be unsophisticated, the harder part will be to understand what data can be reused and how.
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

## Detailed design: compiler layer

### Caching

- Cache data to the "obj" folder, next to other intermediary compilation information.
psfinaki marked this conversation as resolved.
Show resolved Hide resolved
- Do this during Phase 6 of the compilation, next to writing binaries (`main6`).
- Store the data either in binary or in text, as with other things in "obj". The decision can maybe be made based on the speed of serialization/deserialization of different formats.

### Reusing

- Start reading data asynchronously in the beginning of compilation, around importing assemblies (beginning of `main1`).
- Await the data just before the type check (middle of `main1`).
- If there is no data, do type check as usual.
- If there is some data, see what can be reused.
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

### What data to store?
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

- Start with storing full typecheck data.
- Later parsing data can be added if we find a good scenario for having just that.
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

### How to reuse data?

- Be defensive - if there's not 100% guarantee something can be reused, better just invalidate it.
- We need to understand how to reuse data **partially**. Probably can be deduced based on AST diff in parsing?
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

### How to test this?

- Have a feature flag for this: applying it to current type checking tests shouldn't make any difference in results.
- Unit tests: original code + partial typecheck results + reusing them = original code + fresh typecheck

### How to bench this?

- Add benchmarks to the FCSBenchmarks project
- A good inspiration can be workflow-style tests for updating files done by @0101 in Transparent Compiler

---

## Detailed design: tooling layer

-- TO BE DONE --
Loading