Repository navigation
Fix performance of KSClassDeclaration.getAllSuperTypes
#3213
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
Open
jaschdoc
wants to merge
4
commits into
main
Choose a base branch
from
perf-supertypes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...-analysis-api/src/test/kotlin/com/google/devtools/ksp/processor/AllSuperTypesProcessor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * Copyright 2010-2026 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.devtools.ksp.processor | ||
|
|
||
| import com.google.devtools.ksp.getAllSuperTypes | ||
| import com.google.devtools.ksp.getClassDeclarationByName | ||
| import com.google.devtools.ksp.processing.Resolver | ||
| import com.google.devtools.ksp.symbol.KSAnnotated | ||
|
|
||
| class AllSuperTypesProcessor(val classNames: List<String>, override val enableNewFeatures: Boolean) : | ||
| AbstractTestProcessor() { | ||
| private val results: MutableList<String> = mutableListOf() | ||
|
|
||
| override fun toResult(): List<String> { | ||
| return results | ||
| } | ||
|
|
||
| override fun process(resolver: Resolver): List<KSAnnotated> { | ||
| classNames.forEach { className -> | ||
| resolver.getClassDeclarationByName(className) | ||
| ?.getAllSuperTypes() | ||
| ?.forEach { type -> | ||
| results.add(type.declaration.qualifiedName!!.asString()) | ||
| } | ||
| } | ||
| return emptyList() | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
...api/src/test/kotlin/com/google/devtools/ksp/processor/AllSuperTypesRepeatableProcessor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * Copyright 2010-2026 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.devtools.ksp.processor | ||
|
|
||
| import com.google.devtools.ksp.getAllSuperTypes | ||
| import com.google.devtools.ksp.getClassDeclarationByName | ||
| import com.google.devtools.ksp.processing.Resolver | ||
| import com.google.devtools.ksp.symbol.KSAnnotated | ||
| import com.intellij.util.containers.addIfNotNull | ||
|
|
||
| /** | ||
| * This test asserts that [getAllSuperTypes] is stateless/referentially transparent, | ||
| * i.e. reusing the same sequence gives equal output: | ||
| * ``` | ||
| * val superTypes = ...getAllSuperTypes() | ||
| * superTypes.terminalOperation() == superTypes.terminalOperation() | ||
| * ``` | ||
| */ | ||
| class AllSuperTypesRepeatableProcessor(val classNames: List<String>, override val enableNewFeatures: Boolean) : | ||
| AbstractTestProcessor() { | ||
| private val results: MutableList<String> = mutableListOf() | ||
|
|
||
| override fun toResult(): List<String> { | ||
| return results | ||
| } | ||
|
|
||
| override fun process(resolver: Resolver): List<KSAnnotated> { | ||
| classNames.forEach { className -> | ||
| val superTypes = resolver.getClassDeclarationByName(className)?.getAllSuperTypes() ?: return@forEach | ||
| results.add("Original:") | ||
| superTypes.mapNotNull { it.declaration.qualifiedName?.asString() }.forEach(results::addIfNotNull) | ||
|
|
||
| results.add("Copy:") | ||
| superTypes.mapNotNull { it.declaration.qualifiedName?.asString() }.forEach(results::addIfNotNull) | ||
|
|
||
| // Apply terminal operation that does not consume the entire sequence. | ||
| superTypes.any { it.declaration.qualifiedName?.asString() == "L03b" } | ||
|
|
||
| results.add("After Partial:") | ||
| superTypes.mapNotNull { it.declaration.qualifiedName?.asString() }.forEach(results::addIfNotNull) | ||
| } | ||
| return emptyList() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * Copyright 2010-2026 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // TEST PROCESSOR: AllSuperTypesProcessor | ||
| // PROCESSOR INPUT: Leaf | ||
| // EXPECTED: | ||
| // L30a | ||
| // L30b | ||
| // L29a | ||
| // L29b | ||
| // L28a | ||
| // L28b | ||
| // L27a | ||
| // L27b | ||
| // L26a | ||
| // L26b | ||
| // L25a | ||
| // L25b | ||
| // L24a | ||
| // L24b | ||
| // L23a | ||
| // L23b | ||
| // L22a | ||
| // L22b | ||
| // L21a | ||
| // L21b | ||
| // L20a | ||
| // L20b | ||
| // L19a | ||
| // L19b | ||
| // L18a | ||
| // L18b | ||
| // L17a | ||
| // L17b | ||
| // L16a | ||
| // L16b | ||
| // L15a | ||
| // L15b | ||
| // L14a | ||
| // L14b | ||
| // L13a | ||
| // L13b | ||
| // L12a | ||
| // L12b | ||
| // L11a | ||
| // L11b | ||
| // L10a | ||
| // L10b | ||
| // L09a | ||
| // L09b | ||
| // L08a | ||
| // L08b | ||
| // L07a | ||
| // L07b | ||
| // L06a | ||
| // L06b | ||
| // L05a | ||
| // L05b | ||
| // L04a | ||
| // L04b | ||
| // L03a | ||
| // L03b | ||
| // L02a | ||
| // L02b | ||
| // L01a | ||
| // L01b | ||
| // T00 | ||
| // kotlin.Any | ||
| // END | ||
|
|
||
| // FILE: main.kt | ||
|
|
||
| interface T00 | ||
| interface L01a : T00; interface L01b : T00 | ||
| interface L02a : L01a, L01b; interface L02b : L01a, L01b | ||
| interface L03a : L02a, L02b; interface L03b : L02a, L02b | ||
| interface L04a : L03a, L03b; interface L04b : L03a, L03b | ||
| interface L05a : L04a, L04b; interface L05b : L04a, L04b | ||
| interface L06a : L05a, L05b; interface L06b : L05a, L05b | ||
| interface L07a : L06a, L06b; interface L07b : L06a, L06b | ||
| interface L08a : L07a, L07b; interface L08b : L07a, L07b | ||
| interface L09a : L08a, L08b; interface L09b : L08a, L08b | ||
| interface L10a : L09a, L09b; interface L10b : L09a, L09b | ||
| interface L11a : L10a, L10b; interface L11b : L10a, L10b | ||
| interface L12a : L11a, L11b; interface L12b : L11a, L11b | ||
| interface L13a : L12a, L12b; interface L13b : L12a, L12b | ||
| interface L14a : L13a, L13b; interface L14b : L13a, L13b | ||
| interface L15a : L14a, L14b; interface L15b : L14a, L14b | ||
| interface L16a : L15a, L15b; interface L16b : L15a, L15b | ||
| interface L17a : L16a, L16b; interface L17b : L16a, L16b | ||
| interface L18a : L17a, L17b; interface L18b : L17a, L17b | ||
| interface L19a : L18a, L18b; interface L19b : L18a, L18b | ||
| interface L20a : L19a, L19b; interface L20b : L19a, L19b | ||
| interface L21a : L20a, L20b; interface L21b : L20a, L20b | ||
| interface L22a : L21a, L21b; interface L22b : L21a, L21b | ||
| interface L23a : L22a, L22b; interface L23b : L22a, L22b | ||
| interface L24a : L23a, L23b; interface L24b : L23a, L23b | ||
| interface L25a : L24a, L24b; interface L25b : L24a, L24b | ||
| interface L26a : L25a, L25b; interface L26b : L25a, L25b | ||
| interface L27a : L26a, L26b; interface L27b : L26a, L26b | ||
| interface L28a : L27a, L27b; interface L28b : L27a, L27b | ||
| interface L29a : L28a, L28b; interface L29b : L28a, L28b | ||
| interface L30a : L29a, L29b; interface L30b : L29a, L29b | ||
|
|
||
| abstract class Leaf : L30a, L30b |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.