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

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

Open
2 of 4 tasks
IgnatBeresnev opened this issue Feb 24, 2023 · 2 comments · Fixed by #3094
Open
2 of 4 tasks

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

IgnatBeresnev opened this issue Feb 24, 2023 · 2 comments · Fixed by #3094
Assignees
Labels
enhancement An issue for a feature or an overall improvement epic A large body of work that is broken down into smaller issues topic: K2 Issues / PRs that are related to the K2 migration. See #2888
Milestone

Comments

@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Feb 24, 2023

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 IgnatBeresnev added the enhancement An issue for a feature or an overall improvement label Feb 24, 2023
@IgnatBeresnev IgnatBeresnev added this to the Stable milestone Feb 24, 2023
@vmishenev vmishenev self-assigned this Mar 2, 2023
@vmishenev vmishenev linked a pull request May 12, 2023 that will close this issue
@vmishenev vmishenev linked a pull request Jul 26, 2023 that will close this issue
@IgnatBeresnev IgnatBeresnev added the epic A large body of work that is broken down into smaller issues label Aug 11, 2023
@IgnatBeresnev IgnatBeresnev changed the title Migrate Dokka's analysis to K2 compiler Migrate Dokka's analysis to the K2 compiler API Aug 24, 2023
@IgnatBeresnev
Copy link
Member Author

IgnatBeresnev commented Aug 24, 2023

The K2 analysis prototype has been imlpemented in #3094 🎉

Currently, the following projects are supported:

  • All Kotlin/JVM projects that only use Kotlin's Standard Library (so no Java SE API or any 3rd party libraries). On any JVM version.
  • Kotlin/JVM project that use Java SE API directly (for example, import java.util.HashMap) only work if it's Java >= 9, because non-modularized Java (JCL) is not 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 IgnatBeresnev reopened this Aug 28, 2023
@IgnatBeresnev IgnatBeresnev added the topic: K2 Issues / PRs that are related to the K2 migration. See #2888 label Oct 13, 2023
@IgnatBeresnev
Copy link
Member Author

IgnatBeresnev commented Dec 12, 2023

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An issue for a feature or an overall improvement epic A large body of work that is broken down into smaller issues topic: K2 Issues / PRs that are related to the K2 migration. See #2888
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants