Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.4k stars 402 forks source link

Migrate Dokka's analysis to the K2 compiler API #2888

Open IgnatBeresnev opened 1 year ago

IgnatBeresnev commented 1 year ago

Background

Dokka depends on the Kotlin compiler to analyze source code and KDoc comments.

Kotlin's K2 compiler has been in the works for some time, and it is going stable in Kotlin 2.0.

That means that the K1 compiler API that Dokka uses will be phased out over time, and Dokka should migrate its analysis to use the new K2 compiler API.

Steps

There are 4 major steps to make this migration happen:

1. Extract K1 analysis from dokka-base (✅)

The current K1 analysis is deeply ingrained in dokka-base, with internal compiler types being exposed in public API and used by downstream plugins. This makes the migration to K2 very painful both for maintainers and for downstream users.

K1 analysis should be extracted from dokka-base, and a common analysis-api abstraction should be introduced, making it possible for K1 and K2 implementations to coexist at the same time and be used interchangeably.

Update: This step has been done, see #3099 for more details.

2. Implement a prototype to identify blockers (✅)

K2 already provides some semi-stable API that Dokka can use. We should migrate as much of the analysis as possible to identify the missing API and other blocking issues that would need to be addressed by the compiler team.

3. Stabilize JVM-only projects (In Progress)

Kotlin/JVM projects should be easier to support and debug on, so this is the first step in migrating users to the new K2 analysis.

Once generating documentation for Kotlin/JVM projects is stable enough, we will enable K2 analysis by default for such projects.

4. Stabilize KMP projects (semi-blocked)

Once Kotlin/JVM projects are stabilized, the only thing left will be to support Kotlin Multiplatform projects. This is a separate step as it will likely require more time to test it and support less trivial parts of KMP, such as native libraries.

While some KMP projects do already work, there are many corner cases and issues that need to be fixed, both on Dokka's side and in Analysis API.

Blocking issues:

Technical debt

A collection of issues and TODOs that are not necessarily part of any particular step, but that need to be addressed either during the migration or after it:

Related issues

Have a look at the issues marked with the topic: K2 tag to see what's been done and what still needs to be addressed in relation to this issue.

IgnatBeresnev commented 1 year ago

The K2 analysis prototype has been imlpemented in #3094 :tada:

Currently, the following projects are supported:

However, we are unable to proceed further and stabilize Kotlin/JVM projects until K2 introduces some additional API. A separate issue has been created to keep track of this:


This issue's description has been updated, and additional issues have been created to reflect the current status.

IgnatBeresnev commented 9 months ago

Current status

The team has made significant progress in stabilizing the K2 analysis implementation. Many of our efforts also help find and fix bugs in the K2 IDE plugin, since we share a lot of the underlying analysis logic (same low-level API).

Since the last update, we've been unblocked with stabilizing Kotlin/JVM projects, have fixed the known major issues, and have completed the first iteration of testing Dokka manually on a variety of user projects (#3328).

The subtasks have been updated accordingly, they now include the newly discovered bugs and other issues.

We will proceed with stabilizing Kotlin/JVM projects in the near future, aiming to enable K2 for them by default in Dokka 2.0.0, possibly making it available for public testing before the release. Once Kotlin/JVM projects are stable, we'll switch to KMP projects, aiming to enable K2 for them by default in Dokka 2.1.0, but we'll do it sooner if possible (Dokka depends a lot on the upstream API issues).


The API that Dokka uses for K2 analysis is not yet stable, so we encounter various issues and bugs, which we report to Kotlin's YouTrack. Analysis API issues that affect Dokka in one way or another are marked with the kt-analysis-dokka tag in YouTrack.

I'll leave a list of issues below for future reference.

Bugs affecting Kotlin/JVM projects:

KMP-specific issues:

API stabilization issues:

Noticeable differences in Dokka's behaviour that likely come from the upstream Analysis API, but it's undecided if they are bugs, so no YouTrack tickets yet:

vmishenev commented 3 weeks ago

Current status

We are fixing some issues discovered after the second iteration of testing. TBD...

User-affective issues (28):

Small impact on a user (5):

Non-user-affective (5):