123456789_123456789_123456789_123456789_123456789_

TypeProf milestones and TODOs

Big milestones

Rails support

There are many known issues for the analysis of typical Ruby programs including Rails apps.

Currently, projects called gem_rbs and rbs_rails are in progress. The former provides several RBS files for some major gems including Rails. The latter is a tool to generate RBS prototype of a target Rails application by introspection (executing it and monitoring DB schema, etc). TypeProf can use their results to improve analysis precision and performance.

What we need to do:

Error detection and diagnosis feature

At present, TypeProf focuses on generation of RBS prototype from no-type-annotated Ruby code. However, it is possible for TypeProf to report possible errors found during the analysis. In fact, an option -v experimentally shows possible errors found. There are some reasons why it is disabled by default:

For (1), we will research how we can avoid false positives to support typical Ruby coding patterns as much as possible. The primary way is to improve the analysis precision, e.g., enhancing flow-sensitive analysis. If the S/N ratio of an error type is too low, we need to consider to suppress the kind of reports. Also, we may try allowing users to guide TypeProf to analyze their program well. (The simplest way is to write inline type casts in the code, but we need to find more Ruby/RBS way.) We may also explore a "TypeProf-friendly coding style" which TypeProf can analyze well. (In principle, the plainer code is, the better TypeProf can analyze.)

For (2), currently, TypeProf checks the argument types of a call to a method whose type signature is declared in RBS. However, it does not check the return type yet. Redefinition of constants should be warned too. We will survey what errors and warnings TypeProf can print, and evaluate the S/N ratio of each report.

For (3), since TypeProf uses whole program analysis, an error may be reported at a very different place from its root bug. Thus, if TypeProf shows a possible type error, a diagnosis feature is needed to answer why TypeProf thinks that the error may occur. TypeProf has already implemented a very primitive diagnosis feature, Kernel#p, to check what type an expression has. Another idea is to create a pseudo backtrace why TypeProf thought the possible type error may occur. We should consider this feature with LSP support.

Performance improvement

Currently, TypeProf is painfully slow. Even if a target application is small.

The main reason is that TypeProf analyzes not only the application code but also library code: if an application requires "foo", TypeProf actually loads foo.rb even from a gem, and furthermore, if foo.rb requires "bar", it loads bar.rb recursively.

RBS will help to stop this cascade; when an application requires "foo", TypeProf loads sig/foo.rbs instead of foo.rb if the foo gem contains both. Such a RBS file is optional for TypeProf but required for Steep. So, we think many gems will eventually equip their RBS declarations.

That being said, we should continue to improve the analysis performance of TypeProf. We have some ideas.

Language Server Protocol (LSP) support

In the future, we want TypeProf to serve as a language server to show the result in IDE in real-time. However, the current analysis approach is too slow for IDE. So we need to improve the performance first.

Even if TypeProf becomes fast enough, its approach has a fundamental problem. Since TypeProf uses whole program analysis, one edit may cause a cascade of propagation: if a user write foo(42), an Integer is propagated to a method foo, and if foo passes its argument to a method bar, it is propagated to bar, ... So, a breakthrough for LSP may be still needed, e.g, limiting the propagation range in real-time analysis, assuming that a type interface of module boundary is fixed, etc.

Relatively smaller TODOs